jQuery的Ajax响应:作品在浏览器中,空对移动设备 [英] jQuery Ajax Response: Works in Browser, Null on Mobile Device

查看:101
本文介绍了jQuery的Ajax响应:作品在浏览器中,空对移动设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里的第一篇文章。我有什么,我认为这是一个与安全相关的问题,但我真的不知道。

我建设使用PhoneGap的(基本上是一个HTML页面用jQuery / CSS)的移动应用程序。我有一个电话出去到的.asmx web服务,像这样:

  $。阿贾克斯({
    键入:POST,
    网址:http://mydomain.com/customPage.asmx/LoginMember
    数据:memberData,
    的contentType:应用/ JSON的;字符集= UTF-8,
    数据类型:JSON,
    成功:函数(MSG){
            警报(这是我的短信:+味精);
    },
    错误:authenticateFailed
    });
 

当我测试这个用我的桌面上(Mac,Safari浏览器),调用成功。我的味精变量包含一些字符串格式的XML。都好。下面是我的提醒显示,当调用成功和数据存在:

<$p$p><$c$c><User><Membership><Item>MemberLoginStatus</Item><Type>XML</Type><Status>1</Status><Description>Succeeded</Description></Membership></User>

但是,当我采取相同的code,并将其移动到我的设备(iPhone,PhoneGap的),别的事情发生。呼叫仍然是成功的,我的成功功能大火,但我的'味精'变量没有数据。我得到这个警告:这是我的短信:空

我试图研究这个,但似乎无法找出什么问题的实际来源可能。我不认为这是我的code,但我不能确定它是否是一个问题与jQuery,PhoneGap的,或别的东西完全。

截至目前,我最好的猜测是它的一些安全问题。我注意到,当我测试的浏览器,我得到同样的'空'的反应,因为我做我的设备上。难道这可能是由于同源策略?

我已经试过张贴我的问题到PhoneGap的谷歌集团,jQuery的论坛,并没有太多的爱。我将非常AP preciate任何想法/建议,而且我希望其他人在此之前,遇到这种类型的行为。

谢谢! -Felix

//编辑:固定的URL错字。添加成功的响应数据。

解决方案

好了,问题是,我是个白痴。我在测试上的域是一个子域,并在此基础之上......这不是一个公共网站。我在我的主机的IP地址在我的机器上的文件,而不是对(当然)我的iPhone。

当我尝试在不同的/公共网站,我们在这里测试...我现在看到我的设备上的数据。

感谢这么多的豪驰和typeof运算,为您及时与多个回复。所有其他的网站,我张贴了我的问题,你们是令人难以置信的快速与张贴了一些想法。特别是,它的typeof的问题,关于让我思考和认识,其中从错误中传来的域。

我现在觉得我一直在试图用我的钥匙进入我的家......我已经站在了错误的屋前。令人难以置信的尴尬。但我看到的数据,现在,这是最重要的。

再次感谢!

first post here. I have what I think is a security-related question, but I'm honestly not sure.

I'm building a mobile app using PhoneGap (basically an HTML page with jQuery/CSS). I have a call out to a .asmx webservice, like so:

$.ajax({ 
    type: "POST", 
    url: "http://mydomain.com/customPage.asmx/LoginMember", 
    data: memberData, 
    contentType: "application/json; charset=utf-8", 
    dataType: "json", 
    success: function(msg) { 
            alert("This is my message: " + msg); 
    }, 
    error: authenticateFailed 
    }); 

When I test this using my desktop (Mac, Safari), the call is successful. My 'msg' variable contains some string-formatted XML. All good. Here's what my alert shows when the call is successful and data exists:

<User><Membership><Item>MemberLoginStatus</Item><Type>XML</Type><Status>1</Status><Description>Succeeded</Description></Membership></User>

But when I take the same code and move it onto my device (iPhone, PhoneGap), something else happens. The call is still successful and my success function fires, but my 'msg' variable has no data. I get this alert: "This is my message: null"

I've tried researching this, but can't seem to pinpoint what the actual source of the problem could be. I don't think it's my code, but am unsure whether it's an issue with jQuery, PhoneGap, or something else entirely.

As of now, my best guess is it's some kind of security issue. I noticed that when I test in Chrome, I get the same 'null' response as I do on my device. Could this possibly be due to the "Same Origin Policy?"

I've tried posting my question to the PhoneGap Google Group, the jQuery Forum, and haven't had much love. I would greatly appreciate any thoughts/advice, and am hoping someone else here has encountered this type of behavior before.

Thanks! -Felix

//Edit: Fixed url typo. Added successful response data.

解决方案

Ok, so the issue is that I'm an idiot. The domain I was testing on was a subdomain and on top of that... it's not a public site. I have the IP address in my hosts file on my machine, but (of course) not on my iPhone.

When I tried testing on a different/public site we have here... I now see data on my device.

Thanks so much Haochi and typeof, for your prompt and multiple replies. Out of all the other sites where I posted my question, you guys were incredibly quick with posting up some thoughts. In particular, it was typeof's question about the domain that got me thinking and realizing where the error came from.

I now feel like I've been trying to use my key to get into my house... and I've been standing in front of the wrong house. Incredibly embarrassing. But I see data now, and that's all that matters.

Thanks again!

这篇关于jQuery的Ajax响应:作品在浏览器中,空对移动设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆