Does Windows Phone 8 support JQuery Mobile ajax call?

  • 4
  • Question
  • Updated 4 years ago
Does Windows Phone 8 support a JQuery Mobile ajax call? I'm using:

$.ajax({
type: 'POST',
url: 'some URL',
data: senddata,
dataType: 'text'
});

This call works on iPhone and Android device but not on Windows 8 Phone. Is anyone using ajax to post to a URL on Windows 8 Phone?
Photo of Customer Service

Customer Service

  • 15 Posts
  • 0 Reply Likes

Posted 6 years ago

  • 4
Photo of Customer Service

Customer Service

  • 15 Posts
  • 0 Reply Likes
Found a thread that states PhoneGap 3.x does not support ajax calls on Windows 8 platform: https://github.com/jquery/jquery-mobi...

Apparently, it's a PhoneGap framework bug. Older PhoneGap versions does support standard ajax calls.
Photo of Eddy Verbruggen

Eddy Verbruggen, Champion

  • 375 Posts
  • 86 Reply Likes
I found that when using JQM on WP8 I need to add '$.support.cors = true' like this:

$(document).bind("mobileinit", function() {
  $.support.cors = true;
  // all your other jqm init stuff
});
Photo of ismael jimoh

ismael jimoh

  • 4116 Posts
  • 192 Reply Likes
Hi All,

Do you still need help on this topic?

Thanks.
Photo of Customer Service

Customer Service

  • 15 Posts
  • 0 Reply Likes
I have read a few posts that state PhoneGap Build support for WP8 lacks support for ajax calls. Developers say ajax calls stated failing after V2.7. Do you have any plans to fix?

Here is a sample post: https://github.com/jquery/jquery-mobi...
Photo of Ian O'Sullivan

Ian O'Sullivan

  • 24 Posts
  • 0 Reply Likes
Hi Ismael

I also have this issue.
This simple piece of code works for me via the browser but the Phonegap Windows App fails. I've used JSONP in attempt to fix it but again it only works in the browser.

$.ajax('http://fdiapp.com/app_cms/json/sample...',
{
jsonpCallback: 'callback',
dataType: 'jsonp'
})
.success(function(response) {
alert('$.ajax works');
console.log(response);
})
.error(function(response) {
alert('$.ajax fails');
});

This must be affecting a lot of people trying to build Windows apps via Phonegap
Photo of Chris C

Chris C

  • 33 Posts
  • 1 Reply Like
This was supposed to fix this but it I still have a problem.

https://git-wip-us.apache.org/repos/a...

Note I forced 3.5 in my phonegap build by adding this to the config.xml file
Photo of Chris C

Chris C

  • 33 Posts
  • 1 Reply Like
I finally resolved this by this method along with moving to PGB 3.5

http://timcodes.wordpress.com/2013/09...
Photo of Ian O'Sullivan

Ian O'Sullivan

  • 24 Posts
  • 0 Reply Likes
I've confirmed the issue is with PhoneGap Build. Building from Cordova locally works!!!
Photo of Javier Ruiz

Javier Ruiz

  • 23 Posts
  • 1 Reply Like
When I install tha xap file using the "Application Deployment" app Ajax calls runs fine but when I upload it to the windows store and I download it Ajax calls always returns an empty string.
Photo of Chris C

Chris C

  • 33 Posts
  • 1 Reply Like
Javier: Try the solution I posted above. It works in the store for me.

However I am still running into problems with local jumps, but that's another story.
Photo of Javier Ruiz

Javier Ruiz

  • 23 Posts
  • 1 Reply Like
Thanks Chris C, but if I understood this solution is for local calls and my ajax call is to a web service function in a server.
Am I right?
I have found a guy that have exactly the same problem:
http://stackoverflow.com/questions/23...
Photo of Chris C

Chris C

  • 33 Posts
  • 1 Reply Like
I use getJSON for remotes. Works fine.

$.getJSON( "http://www.somewebsite.com/php/get_de... )
.done(function( json ) {
$.each(json, function(key1, item) {
stuff ...
});
})
.fail(function( jqxhr, textStatus, error ) {
var err = textStatus + ", " + error;
console.log( "Request Failed: " + err );
});
Photo of Javier Ruiz

Javier Ruiz

  • 23 Posts
  • 1 Reply Like
I will try
Thanks!
Photo of Javier Ruiz

Javier Ruiz

  • 23 Posts
  • 1 Reply Like
$.getJSON has the same problem, when I submit the app to the store calls fail
Photo of Chris C

Chris C

  • 33 Posts
  • 1 Reply Like
Did you also add these two statements to your config.xml?

<!--trying to avoid windows phone ajax issue-->

earlier versions of phonegap are supposed to have this issue. It defaults to 3.3.
Photo of Javier Ruiz

Javier Ruiz

  • 23 Posts
  • 1 Reply Like
Sorry I don't understand you which two statements are referring you?
Photo of Chris C

Chris C

  • 33 Posts
  • 1 Reply Like
Hah. They were removed from the post since it was code :-)

(access origin="*" /) <!--trying to avoid windows phone ajax issue-->
(preference name="phonegap-version" value="3.5.0" /)

Using ( instead of <
Photo of Javier Ruiz

Javier Ruiz

  • 23 Posts
  • 1 Reply Like
Yes I have this
Photo of Javier Ruiz

Javier Ruiz

  • 23 Posts
  • 1 Reply Like
Could you send me a simple project with an ajax call for see the code and try it?
Photo of Chris C

Chris C

  • 33 Posts
  • 1 Reply Like
I don't have a simple project and am overwhelmed right now to create one, plus I have no way to test Windows Phone. My testers do that for me. This segment for jqmobile is what I use often. Its really simple but basically the same as I posted above plus the two config.xml statements.


$.ajax({
type: 'get',
url: 'channels.html',
isLocal: true,
dataType:"html"
})
.done( function(data) {
var text = $(data).find('div.ui-content .wrapper .scroller');
$("#communications .wrapper").empty();
$("#communications .wrapper").append(text);
$(':mobile-pagecontainer').enhanceWithin();
setDetailsScroller();
$.mobile.loading('hide');
}) // done
.fail(function(jqXHR, status, err){
$.mobile.loading('hide');
alert("Status:"+status+", error code:"+err);
});

Photo of Javier Ruiz

Javier Ruiz

  • 23 Posts
  • 1 Reply Like
I was using success option instead done, I'm going to try with done, thanks :-)
Photo of Chris C

Chris C

  • 33 Posts
  • 1 Reply Like
FWIW I am using jQuery JavaScript Library v1.10.2
Photo of Javier Ruiz

Javier Ruiz

  • 23 Posts
  • 1 Reply Like
I have tried with the done method and the same problem, with the xap deployment toll works but downloading from the store not.
I can't believe that nobody has this problem...
Photo of Identitet Design

Identitet Design

  • 3 Posts
  • 0 Reply Likes
This is still an issue with PhoneGap Build.

Ajax calls return an empty string when the app is uploaded/downloaded from the Windows App Store (it works while testing locally with the app deployment).
Photo of Javier Ruiz

Javier Ruiz

  • 23 Posts
  • 1 Reply Like
I have found the solution, put
< feature name="http://api.phonegap.com/1.0/network"/ >
in your config.xml and it will works perfectly
Photo of Mike Garde

Mike Garde

  • 6 Posts
  • 0 Reply Likes
Thank you so much, this had me floored for a couple of weeks, ios & android worked fine, but not winphone. you're a life saver!
Photo of Guillermo Acosta

Guillermo Acosta

  • 1 Post
  • 0 Reply Likes
Gracias Javier, esa es la solucion.
Thanks Javier, that resolve trouble.