总是在Ajax jquery中失败

时间:2015-01-29 08:49:15

标签: jquery ajax

我总是收到失败的消息,但功能已成功执行。这是我的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();
    }

}

1 个答案:

答案 0 :(得分:3)

不要回显变量$num_updated

并替换,

带有return "Sucessfn";

echo "Sucessfn"; 带有return "Failurefn";

echo "Failurefn";