PhoneGap Ajax Request returns 502 (bad gateway) while on AT&T data but not on WiFi
Using PhoneGap to make an iOS app, I am doing something really simple (making an ajax request to a remote API). While testing on my physical device (iPhone 4) Everything works fine when I make my request when using WiFi but when i make my requests over AT&T data plan I get a 502 bad gateway response (below). I feel it is in the PhoneGap connection class but I could could be wrong... I know my server is receiving the request properly as it creating a instance in my database on either data connection, it is just the response is borked while on AT&T data.
Here is my printout of my AJAX and the error param
$.ajax(
{
url : 'http://remotehost.com/api/users/login',
type : 'POST',
dataType : 'json',
data : $('#user_login').serializeArray(),
success : function(result)
{
}
});
2011-10-10 00:05:12.983 Emoome[481:707] [INFO] Object:
readyState = 4
setRequestHeader = function (a, b) {t===0&&(l[a.toLowerCase()]=b);return this;}
getAllResponseHeaders 开发者_StackOverflow= function () {return t===2?m:null;}
getResponseHeader = function (a) {var b;if(t===2){if(!n){n={};while(b=bs.exec(m))n[b[1].toLowerCase()]=b[2]}b=n[a.toLowerCase()]}return b||null;}
abort = function (a) {a=a||"abort",o&&o.abort(a),w(0,a);return this;}
promise = function (a, c) {if(a==null){if(e)return e;e=a={}}c=z.length;while(c--)a[z[c]]=b[z[c]];return a;}
isRejected = function () {return c||b;}
isResolved = function () {return c||b;}
fail = function () {if(!e){var c=arguments,g,h,i,j,k;b&&(k=b,b=0);for(g=0,h=c.length;g<h;g++)i=c[g],j=d.type(i),j==="array"?f.done.apply(f,i):j==="function"&&a.push(i);k&&f.resolveWith(k[0],k[1])}return this;}
done = function () {if(!e){var c=arguments,g,h,i,j,k;b&&(k=b,b=0);for(g=0,h=c.length;g<h;g++)i=c[g],j=d.type(i),j==="array"?f.done.apply(f,i):j==="function"&&a.push(i);k&&f.resolveWith(k[0],k[1])}return this;}
then = function (a, c) {b.done(a).fail(c);return this;}
success = function () {if(!e){var c=arguments,g,h,i,j,k;b&&(k=b,b=0);for(g=0,h=c.length;g<h;g++)i=c[g],j=d.type(i),j==="array"?f.done.apply(f,i):j==="function"&&a.push(i);k&&f.resolveWith(k[0],k[1])}return this;}
error = function () {if(!e){var c=arguments,g,h,i,j,k;b&&(k=b,b=0);for(g=0,h=c.length;g<h;g++)i=c[g],j=d.type(i),j==="array"?f.done.apply(f,i):j==="function"&&a.push(i);k&&f.resolveWith(k[0],k[1])}return this;}
complete = function () {if(!e){var c=arguments,g,h,i,j,k;b&&(k=b,b=0);for(g=0,h=c.length;g<h;g++)i=c[g],j=d.type(i),j==="array"?f.done.apply(f,i):j==="function"&&a.push(i);k&&f.resolveWith(k[0],k[1])}return this;}
statusCode = function (a) {if(a){var b;if(t<2)for(b in a)k[b]=[k[b],a[b]];else b=a[v.status],v.then(b,b)}return this;}
responseText = <html><body><h1>502 Bad Gateway</h1>
The server returned an invalid or incomplete response.
</body></html>
status = 502
statusText = error
I finally figured out the dang problem. Had nothing to do with AT&T or PhoneGap... well still not exactly sure if the former is not responsible as AT&T is shady... The issue was actually in my CodeIgniter REST server- my app was creating a new session entry for each login request (ajax POST request) and somehow when coming back over AT&T's wire my app was deciding this was a 502 error as it was not seeing the cookie or session data.
For anyone still having this issue, I too was having the issue. When I sent a request to the server from my app, I had a setcookie function.
This was exactly what I had: setcookie('like'.$_POST[qid].'', '1', time() + (60 * 60), "/");
As soon as I removed the set cookie, everything worked fine. Very odd.
精彩评论