Php 什么';这个JSON请求有什么问题?
我有一个简单的ajax json请求 以下是客户端javascript:Php 什么';这个JSON请求有什么问题?,php,javascript,ajax,json,Php,Javascript,Ajax,Json,我有一个简单的ajax json请求 以下是客户端javascript: function ajax(){ //alert('hello'); $.ajax({ url: '../ajax/goal_ajax.php', dataType: 'json', success: function( data ){ // success! :D alert('hello');
function ajax(){
//alert('hello');
$.ajax({
url: '../ajax/goal_ajax.php',
dataType: 'json',
success: function( data ){
// success! :D
alert('hello');
}, error: function( data ){
// data.responseText is what you want to display, that's your error.
alert('die');
}
})
//progressBar.set('value',data.total);
//document.getElementById('txtCDInfo').innerHTML=txt;
}
下面是php处理程序:
<?php
include ("../includes/db_con.php");
$itemResults = mysql_query("SELECT `sold_for` FROM `items` WHERE `item_did_sell`='1'") or die();
$mIResults = mysql_query("SELECT `mi_price`, `mi_total_sold` FROM `misc_items` WHERE `mi_total_sold`>'1'") or die();
$donationResults = mysql_query("SELECT `amount` FROM `donations`") or die(mysql_error());
$total = 0;
$itemTotal = 0;
$mITotal = 0;
$donationTotal = 0;
while($row = mysql_fetch_assoc($itemResults)){
$itemTotal += $row['sold_for'];
$total += $itemTotal;
}
while($row = mysql_fetch_assoc($mIResults)){
$mITotal += ($row['mi_price'] * $row['mi_total_sold']);
$total += $mITotal;
}
while($row = mysql_fetch_assoc($donationResults)){
$donationTotal += $row['amount'];
$total += $donationTotal;
}
header("Content-Type: application/json");
echo json_encode(array("items" => $itemTotal, "mitems" => $mITotal, "donations" => $donationTotal, "total" => $total));
include ("../includes/db_discon.php");
?>
编辑:
data.responseText
返回{“items”:1000,“mitems”:0,“捐赠”:0,“total”:1000}
您是否尝试查看FireBug控制台打开(或等效控制台)时发生的情况?有关实际结果,请查看./ajax/goal\u ajax.php
,可能它不是有效的JSON或包含垃圾。data.responseText
包含什么?您确定这是正确的url:“../ajax/goal\u ajax.php”,?可能是您从一个包含的文件发出这个请求,您必须引用相对于请求的php文件的路径,比如'index.php'404?您确定路径正确吗?那么,“我没有收到404错误”是什么意思?
{"items":1000,"mitems":0,"donations":0,"total":1000}