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

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.