为什么我在Sencha HTTP帖子中出错?

时间:2014-08-13 16:38:16

标签: sencha-touch

我完全是Sencha的新手,请原谅我这个天真的问题。

如果我尝试将以下HTTP发布到以下地址https://api.pericoach.xyzhee.com

WS.authenticateUser = function (accountName, pwd, successCallback, errorCallback)
{
console.log('** WS.authenticateUser() **');
console.log('** WS.authenticateUser() >> WS.serverUrl: ' + WS.serverUrl);


$.ajax({
    url: WS.serverUrl + "/Mobile/Login",
    type: "POST",
    data: { username: accountName, password: pwd },
    async : true,
    dataType: 'json',
    statusCode:
    {
        403: function (data) {
            console.log('** WS.authenticateUser -- 403 **');

            //alert("403: " + data.Message);
            callback(data);
        }
    },
    success: function (data, textStatus, jqXHR) 
    {
        console.log('** WS.authenticateUser -- success **');

        //alert("success: " + data.Message + " - " + data.Token + " - " + data.TokenDate);
        successCallback(data);
    },
    error: function (jqXHR, textStatus, errorThrown)
    {
        console.log('** WS.authenticateUser -- error **');

        errorCallback();
    }
});
};

用户=患者

密码=密码123

但总是错误回调被调用!!

errorThrown = SyntaxError: Unexpected end of input

如果我尝试像Postman这样的东西,我会得到以下结果:

{
"Message": null,
"Token": "40684f9d-ebab-433c-acaf-fddf5204a3b9",
"TokenDate": "21/07/2014 12:00:00 AM",
"Username": "Patient",
"FirstName": "Patient",
"LastName": "Name",
"PatientID": "26cb7141-a624-4fd1-adfd-06a8ebf2025c",
"PatientSFID": null,
"ClinicianID": "00000000-0000-0000-0000-000000000000",
"UserType": 1,
"Success": true,
"SubscriptionExpired": false
}

1 个答案:

答案 0 :(得分:2)

如果它可能对其他人有用:

域名白名单(请参阅PhoneGap文档)

<access origin="*" />

这解决了这个问题!