Answered by:
Using JQuery to call web service returns timeout

Question
-
I'm having issues with calling a webservice using a Jquery. using XHR works fine. Other jQuery functionality (binding clicks, element selector, etc) are also fine.
$.ajax({ url: baseUrl + "/apijsonp/post", data: { // ... }, dataType: "jsonp", type: "GET", processData: true, contentType: "application/json; charset=utf-8", timeout: 10000, error: function (xhr, status, e) { var a = xhr; var b = status; var c = e; } });
execution goes to error function. e = timeout.
I've also tried using jQuery.support.cors = true as advised in http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/66273417-92cd-4a35-b9a1-281d962eff59. but that doesn't seem to change anything. the callback function wasn't called.
However, using xhr like below works:
WinJS.xhr({ url: url}).then( function (result) { // ... }, function (result) { // ... });
Is JQuery's web request stack no longer supported in Consumer Preview?
Friday, May 11, 2012 7:46 PM
Answers
-
Hi Ronald,
We have many people using jQuery successfully.
Some hints:
1. Do not include <script> blocks in your html files. Move all your jQuery logic into the page.js file for your pages.
2. Ensure you make jQuery calls after the ready: function in pages and/or after the app is initialized and you call WinJS.UI.ProcessAll();
Short of that, you can go up to the forms that support jQuery and see if others have experienced this and how to work around the problem.
-Jeff
Jeff Sanders (MSFT)
- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Friday, May 11, 2012 7:58 PM
- Marked as answer by Ronald Widha Saturday, May 12, 2012 6:09 AM
Friday, May 11, 2012 7:58 PMModerator
All replies
-
Hi Ronald,
We have many people using jQuery successfully.
Some hints:
1. Do not include <script> blocks in your html files. Move all your jQuery logic into the page.js file for your pages.
2. Ensure you make jQuery calls after the ready: function in pages and/or after the app is initialized and you call WinJS.UI.ProcessAll();
Short of that, you can go up to the forms that support jQuery and see if others have experienced this and how to work around the problem.
-Jeff
Jeff Sanders (MSFT)
- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Friday, May 11, 2012 7:58 PM
- Marked as answer by Ronald Widha Saturday, May 12, 2012 6:09 AM
Friday, May 11, 2012 7:58 PMModerator -
You're right, I can get it to work by a simple:
$.getJSON(url, function (data) { console.log(data.results[0].text); }).error (function (e) { var exception = e; });
Windows 8 IE runtime doesn't even need jsonp (there isn't seem a cross domain request check for ws call - which kinda make sense since the js app is local).
I think the problem that I had was serializing/deserializing jsonp and somehow causes timeout.Thanks
Saturday, May 12, 2012 6:10 AM