douqiao2471 2014-05-12 17:35
浏览 51

ajax成功回调不能处理json响应

AJAX request was successfully sent to php server and also inserted records on my oracle database. I cannot get the JSON response in success, error, complete callback functions.

I can't also see any logs on console.log

I am using codeigniter and my php server was on model folder and it returns an json formatted string.

echo json_encode(array("Response"=>99,"Value"=> $result));

Here is my ajax code:

$.ajax({
    url: 'url/functionhere',
    type: 'post',
    dataType: 'json',
    data: {
        "STUDID": studId,
            "LASTNAME": lastName,
            "FIRSTNAME": firstName,
            "MIDINITIAL": midInitial,
            "BIRTHDAY": birthday,
            "AGE": age,
            "GENDER": 'M'
    },
    success: function (data) {
        if (data.Response == 99) {
            alert(data.Value);
            console.log("putek");
        }
    },
    error: function (header, status, error) {
        console.log('ajax answer post returned error ' + header + ' ' + status + ' ' + error);

    },
    complete: function () {
        console.log("putek");
    }
});
  • 写回答

2条回答 默认 最新

  • dongxing1960 2014-05-12 18:19
    关注

    You might also want to give this a try (using jQuery 1.9.1):

     var args=new Object();
     args["STUDID"]=studId;
     args["LASTNAME"]=lastName;
     args["FIRSTNAME"]=firstName;
     args["MIDINITIAL"]=midInitial;
     args["BIRTHDAY"]=birthday;
     args["AGE"]=age;
     args["GENDER"]='M';
    
     $.post("url/goes/here", args)
     .done(function(returnVal){
         var returnObj = $.parseJSON(returnVal);
         //remaining success code goes here
     })
     .fail(function(){
         //put failure code here
     });
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大