Phonegap iOS Ajax Call

164 views
Skip to first unread message

Federico Fricke

unread,
Aug 8, 2013, 1:42:30 PM8/8/13
to phon...@googlegroups.com
HI,


I having an issue consuming  a RESTful service build in Java.
When I create an Ajax Call to a service I don't get any response (nor failure, nor success).

I have test this issue using jQuery and directly using XMLHttpRequest and I have the same behaviour.


$.ajax({
       type
: "GET",
       url
: appBaseURL + "service" + cookie,
       contentType
: "application/json; charset=utf-8",
       dataType
: "json",
       timeout
: 10000,
       
}).
done(function(){console.log("All done");}).
fail
(function(){console.log("It fail");}).
always
(function(){console.log("Complete");});


var xhrManual = new XMLHttpRequest();
xhrManual
.onreadystatechange = function()
{
    console
.log("Ready State: " + xhrManual.readyState);
   
if ( xhrManual.readyState == 4) {
        console
.log("Ready State 4");
   
}
}
xhrManual
.open("GET",appBaseURL + "service" + cookie,true);
xhrManual
.setRequestHeader('Content-type', 'application/json; charset=utf-8');
xhrManual
.send();


I have tried the following workaround without any luck.
Tested it using the latest version of phonegap (cordova.js 3.0.0-0-ge670de9 and 2.9.0-0-g83dc4bd)
Used jquery 1.10 and 1.11 (I know now that this has nothing to do...)


I believe the issue is related with the returned data. But it doesn't have to do with null; sometimes it fails when the structure is more complex.

If I return this, it doesn't work
[
{"field1":"value1","field2":null},
{"field1":"value1","field2":null},
{"field1":"value1","field2":null}
]


If I return the following it works!

[
{"field1":"value1","field2":""},
{"field1":"value1","field2":""},
{"field1":"value1","field2":""}
]

I have captured the network request using safari web inspector and I get a status 200.



I have tested this in browsers and in Android and it works ok!

Any idea?

Federico Fricke

unread,
Aug 8, 2013, 3:00:09 PM8/8/13
to phon...@googlegroups.com
Just to follow up...
I tried to do the request sync using the XMLHttpRequest and I get the following error:

XMLHttpRequest Exception 101: A network error occurred in synchronous requests.

If I saw the error in Android or in the browser I will immediately point out to the server... but right now I believe that's maybe a combination of between those two.

Federico Fricke

unread,
Aug 8, 2013, 5:31:25 PM8/8/13
to phon...@googlegroups.com
Well i resolve the issue.
The issue was in Jersey.

I will submit another post with the final and cleanest solution.
Right now it's working using:

response.flushBuffer();


On Thursday, August 8, 2013 12:42:30 PM UTC-5, Federico Fricke wrote:
Reply all
Reply to author
Forward
0 new messages