Skip to main content

AJAX to Sharepoint Server with Phonegap and JQuery Mobile not working



I have the following Problem. In the Phonegap App(for Android) I want to make an AJAX-Call to connect with a Sharepoint Server, with the following Code:







$.ajax({

url:"https://xxx/_vti_bin/lists.asmx",



beforeSend: function( xhr ){

xhr.setRequestHeader(

"SOAPAction",

"http://schemas.microsoft.com/sharepoint/soap/GetListCollection"

);

xhr.setRequestHeader("Content-Type","text/xml; charset=utf-8");

},

dataType:"xml",

contentType: "application/xml; charset=utf-8",

timeout:10000,

type:'POST',

cache: false,

username: "username",

password: "password",

data: soapEnv,

success:function(data) {

// alert data

var serializer = new XMLSerializer();

serialized = serializer.serializeToString(data);

alert(serialized);

},

error:function(XMLHttpRequest,textStatus, errorThrown) {

// alert errors

alert("Error status :"+textStatus);

alert("Error type :"+errorThrown);

alert("Error message :"+XMLHttpRequest.responseXML);

alert("Error statustext :"+XMLHttpRequest.statusText);

alert("Error request status :"+XMLHttpRequest.status);

},

complete: function(jqXHR, textStatus){

alert(textStatus);

}

});







When I try to run it on the Android Emulator the error messages are:







Error status: error

Error type:

Error message: undefined

Error statustext: error

Error request status: 0







However when I try to run it on my Browser (Chrome) with disabled websecurity (because of same origin policy) it works all fine. Phonegap normally shouldn't care about SOP because of the file:/// Protocol. I added the following to 'mobileinit':







$(document).bind("mobileinit", function() {

$.support.cors = true;

$.mobile.allowCrossDomainPages = true;

});







But when I run the same Code in Chrome without websecurity disabled, I get exactly the same errors as in the Android Emulator.





I also tried an AJAX call to wikipedia (with html instead of xml, and GET instead of POST), and that worked without a problem.





Also I think the AJAX to Sharepoint doesn't even get fired (no traffic in Fiddler2, if I managed to configure it the right way)





So I am really stuck with this problem since 2 days now, if anyone knows how to make this ajax call work, it would made me so happy :-)





(soapEnv is the XML envelope, sent to the server)


Comments

  1. Well I know that once upon a time jQuery had a bug where it treated a request status of 0 as an error. When running from the file protocol a status of 0 is the same this as a 200 (OK). You may need to update your version of jQuery.

    Alternatively to test my theory just do a plain vanilla XHR request to your service to see if it works. Here is my stock example:

    http://simonmacdonald.blogspot.com/2011/12/on-third-day-of-phonegapping-getting.html

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?