I am confused as to why an alert is not firing a json response. The response is coming into firebug. This was working ok when I was using php4.4.7 but then upgraded to php5.3.5 and now producing this error. Or probably my error. Can someone check my code and see where I am going wrong? If you need any more code, please let me know. many thanks
http://jsfiddle.net/QQtVv/
code here as per request:
function test(com,grid)
{
if (com=='Delete')
{
if($('.trSelected',grid).length>0){
if(confirm('Delete ' + $('.trSelected',grid).length + ' items?')){
var items = $('.trSelected',grid);
var itemlist ='';
for(i=0;i<items.length;i++){
itemlist+= items[i].id.substr(3)+",";
}
$.aj开发者_如何学JAVAax({
type: "POST",
dataType: "json",
url: "fileinrptdelete.php",
data: "items="+itemlist,
success: function(data){
alert("You have successfully deleted:"+"\n\n"+"Customer: "+data.customer+"\n"+"name: "+data.ref+"\n"+"boxref: "+data.boxref);
$("#flex1").flexReload();
}
});
}
} else {
alert('You have to select a row to delete.');
}
}
}
// this is from the file fileinrptdelete.php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-type: text/x-json");
$json = "";
$json .= "{\n";
$json .= "name: '".$ref."',\n";
$json .= "company: '".$customer."',\n";
$json .= "boxref: '".$boxref."',\n";
$json .= "total: $total\n";
$json .= "}\n";
echo $json;
The JSON is invalid (and served with the wrong content-type, it should be application/json).
Don't hand craft it. Use a library.
You are also trying to read data using the variable names you use in PHP and not using the names you apply to the keys in the JSON.
a valid JSON attributes and values must be enclosed in double quotes "name" : "value" other than that it looks okay to me.
精彩评论