我总是收到失败的消息,但功能已成功执行。这是我的ajax电话。
jQuery.ajax({
type: 'POST',
url: "<?php echo $base_url; ?>?q=search/newfunc",
datatype: 'json',
data:{id:id ,data1 : data1},
success: function (returnval) {
alert("success");
var col=[];
$('#mTable').find('td').each(function(index, cell){
col.push($(this).attr("class"));//
});
var id = (col[0].match(/\d+/));
$('table#mTable #dataid').html(newdata);
},// end of function success
error: function(returnval) {
alert("Failure"+id);
}
处理上述问题的功能就是这个;
function search_newfunc()
{
$id = $_REQUEST['id'];
$data1 = $_REQUEST['data1'];
echo $num_updated = db_update('mtable')
->fields(array(
'db_data1' => $data1,
))
->condition('id',$id, '=')
->execute();
if($num_updated)
{
return "Sucessfn";
die();
}
else
{
return "Failurefn";
die();
}
}
答案 0 :(得分:3)
不要回显变量$num_updated
,
并替换,
带有return "Sucessfn";
的 echo "Sucessfn";
带有return "Failurefn";
echo "Failurefn";