我可以得到以下字符串EDITED可以查看JSON響應200 OK,但返回parsererror
([{"data":{"Rate":"","RoleA":"Student","NameA":"student","RoleB":"Tutor","NameB":"tutorB","Give":"0","Get":"1","Accept":"0"}}]);
我從http://api.jquery.com/jQuery.ajax/閱讀,但仍然不知道在哪裏我做錯。
這是我的代碼
$.ajax({
type: 'GET',
dataType: 'jsonp',
jsonpCallback: 'jsoncallback',
data:
{
nameB: nameB,
roleB: roleB,
get123: get123,
accept: accept
},
url: 'http://mydomain.com/check.php?callback=?',
success: function(data){
alert(data[0].data.RoleA);
//alert("ABC");
//if ($("#role").text() == "Tutor")
//{
// window.location.href='tutor_home.html';
//}
//else
//{
// window.location.href='student_home.html';
//}
},
error: function(jqXHR, textStatus){
alert("Request failed: " + textStatus);
}
});
從鉻,我能找到的JSON字符串,它看起來正常。然而,它並沒有提示成功消息,而是它警告parsererror錯誤..我應該改變什麼地方?由於
我的PHP
<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
header("Content-type: application/json");
include('mysqlConfig.php');
$nameB = $_GET["nameB"];
$roleB = $_GET["roleB"];
$get = $_GET["get123"];
$accept = $_GET["accept"];
$sql="SELECT * FROM tbl_rating WHERE NameB='$nameB' and RoleB='$roleB' and Get='$get' and Accept='$accept'";
$result=mysql_query($sql);
$rows = array();
//retrieve and print every record
while($r = mysql_fetch_assoc($result)){
// $rows[] = $r; has the same effect, without the superfluous data attribute
$rows[] = array('data' => $r);
}
// now all the rows have been fetched, it can be encoded
//echo json_encode($rows);
$data = json_encode($rows);
echo $_GET['jsoncallback'] . '(' . $data . ');';
?>
我不知道爲什麼網址如下: 請求URL: http://mydomain.com/check.php?callback=jsoncallback&nameB=tutorB&roleB=Tutor&get123=1&accept=0&_=1363710513593
我不知道它是什麼的最後一個參數&_=1363710513593
?
,但它可以返回上面的字符串
做它關係到jQuery的版本?我使用jquery-1.9.1.min.js
那你試試?你遇到什麼錯誤? (不要指望我們爲你做功課......) – Martijn 2013-03-19 15:16:20
我試圖改變類型從GET到POST,並試圖改變不同的URL,並且他們都警告「有錯誤」。 。 – HUNG 2013-03-19 15:29:43
你能告訴從這個鏈接'HTTP響應://mydomain.com/check.php nameB = tutorB&roleB =導師&get123 = 1&接受= 0&jsoncallback = mycallback' – vittore 2013-03-19 16:11:41