我正在像以前一样运行 AJAX 函数。这一次很奇怪。虽然 XHR 控制台给了我 200/Success,但错误回调一直在发生。
function runNewprop() {
var nurl = 'http://www.mysite.com/myscript.php';
$.ajax({
url: nurl,
dataType: 'json',
success: function(data){
$('#nl_details').html('');
$each(data, function (key, value){
var mlsnum = value[0];
$('#nl_details').append('<div class="nl_list"><h5>'+mlsnum+'</h5></<div>');
});
},
error: function(){
alert('Oops!');
}
});
}
然后是PHP文件:
<?php
$link = mysql_connect('localhost','username','password');
mysql_select_db('singleprop', $link);
$date = mysql_real_escape_string($_GET['date']);
$sort = mysql_real_escape_string($_GET['sort']);
$query = "
SELECT * FROM jos_mls
JOIN jos_activeagents AS active ON singleprop.jos_mls.MSTLISTBRD = active.AGENTUID
JOIN jos_agents AS agents ON active.AGENTUID = agents.AGTBRDIDMM
";
if ($date == 'week') {
$query .= "AND MSTLISTDT >= DATE_ADD(CURDATE(), INTERVAL -7 DAY)";
}
elseif ($date == 'twoweek') {
$query .= "AND MSTLISTDT >= DATE_ADD(CURDATE(), INTERVAL -14 DAY)";
}
elseif ($date == 'month') {
$query .= "AND MSTLISTDT >= DATE_ADD(CURDATE(), INTERVAL -31 DAY)";
}
elseif ($date == 'twomonth') {
$query .= "AND MSTLISTDT >= DATE_ADD(CURDATE(), INTERVAL -62 DAY)";
}
if ($sort == 'agent') {
$query .= " ORDER BY AGTLNAME";
}
elseif ($sort == 'city') {
$query .= " ORDER BY MSTCITY";
}
elseif ($sort == 'zip') {
$query .= " ORDER BY MSTZIP";
}
elseif ($sort == 'county') {
$query .= " ORDER BY MSTCOUNTY";
}
else {
$query .= " ORDER BY MSTLISTDT";
}
$query .= ";";
$result = mysql_query($query);
$data = mysql_fetch_array($result);
return json_encode($data);
mysql_close($link);
?>
我在语法中遗漏了什么吗?当我回显构建的查询并将其复制到我的控制台并运行它时,一切都很顺利。但是当我尝试通过 AJAX 运行它时,我得到了成功/200,但发生了错误回调。