这个ajax调用没有调用,我的代码中缺少什么,任何人都可以解释

时间:2016-11-04 12:01:03

标签: javascript ajax

var userId = window.localStorage.getItem("zicuserId");
var dataString = "deviceId="+myDeviceId + "&userId=" + userId + "&deviceToken=" + myDeviceToken;
alert("dataString: " + dataString);
$.ajax({
        type: POST,
        url: "http://mobilapps.zicoil.pk/fineName.php",
        data: dataString,
        async: false,
        dataType: "text",
        success: function(data)
        {
            window.localStorage.setItem("userDeviceRegister", "true");
            alert(data);
        },
        error: function()
        {
            alert("error , you are in error function.")
        }
    });

2 个答案:

答案 0 :(得分:1)

试试这个。

var userId = window.localStorage.getItem("zicuserId");
var dataString = {deviceId:myDeviceId,userId:userId,deviceToken:myDeviceToken};
alert("dataString: " + dataString);
$.ajax({
        url: "http://mobilapps.zicoil.pk/fineName.php",
        type: "POST",
        data: dataString,
        async: false,
        dataType: "JSON",
        success: function(data)
        {
            window.localStorage.setItem("userDeviceRegister", "true");
            alert(data);
        },
        error: function()
        {
            alert("error , you are in error function.")
        }
    });

答案 1 :(得分:0)

此行中存在语法错误:type: POST,。只需将POST替换为"POST"即可。这个参数应该是字符串,现在它不是定义变量。

BTW:您应该使用浏览器控制台来检测此类错误。