avoision
avoision

Reputation: 1235

jQuery Ajax Response: Works in Browser, Null on Mobile Device

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.

Upvotes: 1

Views: 5306

Answers (2)

avoision
avoision

Reputation: 1235

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!

Upvotes: 3

typeof
typeof

Reputation: 5922

In your code you're missing the begging quote for your url property.

Assuming that's just a typo, have you tried switching User Agents in your desktop safari? (Must enable the Developer Menu item). Switch your User Agent to "iPhone" and see if you get the null response.

Upvotes: 2

Related Questions