我需要获取数组,而不是仅仅将数据推送到 html div 中——取回 php 变量。
我的 $.ajax 帖子----
<script type="text/javascript">
$(function() {
$("#login").click(function() {
var theName = $.trim($("#username").val());
if(theName.length > 0)
{
$.ajax({
type: "POST",
url: "callajaxdemo.php",
data: ({name: theName}),
cache: false,
dataType: "text",
success: onSuccess
});
}
});
$("#resultLog").ajaxError(function(event, request, settings, exception) {
$("#resultLog").html("Error Calling: " + settings.url + "<br />HTTP Code: " + request.status);
});
function onSuccess(data)
{
$("#resultLog").html("Result: " + data);
//$.mobile.changePage('stats.html', { transition: 'slideup'}, true, true);
}
});
</script>'
我的 PHP 文件是 -----
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$host = 'https://api.qpme.com/api/accounts/me';
$process = curl_init($host);
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($process);
$content = json_decode($return);
/*
echo "<pre>";
print_r($content);
echo "</pre>";
*/
print $content->email . "<br>";
print "<h3>" . "Welcome" . ' ' . $content->firstName . ' ' . $content->lastName . '!' . "<h3>";
?>'
目标是取回数组,然后将它的某些部分发布到不同的 jquery 移动页面。