[英]JSONP not working
I am making a jQuery Mobile and PhoneGap app. 我正在制作一个jQuery Mobile和PhoneGap应用程序。 I need to submit a form.
我需要提交一份表格。 I made something like this:
我做了这样的事情:
$.ajax(
{
url: 'http://ip.ip.ip.ip:8070/services/rest/operator/login',//?email=' + email + '&password=' + haslo,
dataType: 'jsonp',
type: 'GET',
callback: 'jsonpCallback',
jsonpCallback: 'jsonpCallback',
jsonp: '_jsonp',
data: ({'email' : email, 'password' : pass}),
contentType: 'application/x-www-form-urlencoded',
success: function (data) {
window.location = ('file:///android_asset/www/custom/main.html');
},
error: function (data) {
alert('Login i/lub hasło nieprawidłowe '+data);
}
});
It works on Chrome but doesn't on my Android device. 它适用于Chrome,但不能在我的Android设备上。 I read the documentation of both PhoneGap and jQuery Mobile, and I tried whitelisting, $.mobile.allowCrossDomainPages and $.support.cors.
我阅读了PhoneGap和jQuery Mobile的文档,并尝试将白名单,$。mobile.allowCrossDomainPages和$ .support.cors列入白名单。 As I know that PhoneGap allows cross-domain I also tried to change datatype to json.
据我所知PhoneGap允许跨域,我也尝试将数据类型更改为json。
Unfortunately I have no access to server-side code. 不幸的是,我无权访问服务器端代码。 I just have this short "wadl".
我只有这个简短的“ wadl”。 Web service returns 200 success or 401 access denied.
Web服务返回200成功或401访问被拒绝。
<resource path="/operator">
<resource path="/login">
<method name="GET">
<request>
<representation mediaType="application/x-www-form-urlencoded">
<param name="email" style="query" type="xs:string"/>
<param name="password" style="query" type="xs:string"/>
</representation>
</request>
<response>
<representation mediaType="application/octet-stream"/>
</response>
What am I missing? 我想念什么?
Note: Only once I received [object Object] error message. 注意:仅在收到[object Object]错误消息之后。 But I have no idea how:)
但我不知道如何:)
Quentin was right. 昆汀是对的。 It was a server-side problem.
这是服务器端的问题。 When using JSONP reqests, server has to provide a response in json format, not only status code.
使用JSONP请求时,服务器必须以json格式提供响应,而不仅仅是状态码。 It was enough to add true and false (properly json formatted) as a response.
添加true和false(正确为json格式)作为响应就足够了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.