Grifflet
Grifflet

Reputation: 31

Phonegap android ajax calls working in browser, not on mobile

I need some help with a phonagap/cordova app, its very basic but I cannot get my ajax calls to work of my mobile to the server, everything works fine in the browser. Please note I use phonegap's online builder to compile my code.

I have tried all of the following:

Now I have looked at whitelist but for some reason it breaks my config file when adding it, then I tried legacy whitelist, then I cannot get it built online on phonegap.

my ajax method:

$("#btnTest").click(function (evt) {
        var value = "";
        var options = {};
        options.url = "http://*/MobileService/ServiceFile.asmx/test";
        options.type = "POST";
        options.data = JSON.stringify({ "data": value });
        options.dataType = "json";
        options.crossDomain = true;
        options.contentType = "application/json";
        options.success = function (result) { $("#error-msg").text(result.d); };
        options.error = function (err) { $("#error-msg").text("Error saving the data!"); };
        console.log(value);
        $.ajax(options);
        evt.preventDefault();
    });

my index.html head tag:

<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>MobileApp</title>
<meta name="viewport" content="width=device-width, initial-scale=1">   
<link href="css/jquery.mobile-1.4.5.min.css" rel="stylesheet" />
<script src="scripts/jquery-2.2.0.min.js"></script>
<script type="text/javascript">
$(document).bind("mobileinit", function () {
    $.support.cors = true;
    $.mobile.allowCrossDomainPages = true;
});
</script>
<script src="scripts/jquery.mobile-1.4.5.min.js"></script>
<script src="scripts/jSignature/jSignature.min.js"></script>
<link href="css/index.css" rel="stylesheet" />

Also note I am using visual studio 2013 to develop in.

Thanks in advance

Upvotes: 1

Views: 541

Answers (1)

Grifflet
Grifflet

Reputation: 31

So to answer my own question, in the end I found the legacy version of the the whitelist plugin.

As soon as I added this to my project it solved the CORS error.

Upvotes: 2

Related Questions