2

We have URL when we hit URL URL in browser we got data. We got Data like

[{"UserId":"c2fbd9fb-a423-4d33-9ea4-3aa58f7b52cf","UserType":"Parent","OutPutMessage":"Sucess"}].

But We need get data through ajax call.we tried like this

window.onload = function (){
 $.ajax({
url:'http://janasenanews.com/MyService.asmx/GetUserLoginVerification',
         data: {
             username:"9440325333",
             password :"9440325333"
         },
         type: "GET",
         dataType: 'JSON',
         success:function(data) {
            alert( data);
              //console.log("Here is the data", data);
         }
    });
    }

But We got two error

Failed to load resource: the server responded with a status of 500 (Internal Server

XMLHttpRequest cannot load  Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 500.

Please guide to us what wrong in our code.

Naveen Dodda
  • 147
  • 1
  • 1
  • 9
  • 2
    Possible duplicate of [Ways to circumvent the same-origin policy](http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy) – Alex Char Nov 02 '15 at 14:09
  • It would be better if you copied the text of the error message into this question. – Will Sheppard Nov 02 '15 at 14:27

2 Answers2

0

Change your script with:

window.onload = function (){
$.ajax({
     url:'http://janasenanews.com/MyService.asmx/GetUserLoginVerification',
     data: {
         username:"9440325333",
         password :"9440325333"
     },
     type: "GET",
     dataType: 'JSON',
     success:function(data) {
        alert( data);
          //console.log("Here is the data", data);
     }
});
}
Viktor Maksimov
  • 1,465
  • 1
  • 10
  • 11
  • we tried as you said we got error Failed to load resource: the server responded with a status of 500 (Internal Server Error) ajaxcalling.html:1 XMLHttpRequest cannot load http://janasenanews.com/MyService.asmx/GetUserLoginVerification?username=9440325333&password=9440325333. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 500. – Naveen Dodda Nov 03 '15 at 06:46
0

From the tags on your question it looks like you are making the ajax request from a Cordova app? If so, you will need to add the Cordova whitelist plugin to your app:

cordova plugin add cordova-plugin-witelist

And then in your config.xml, you'll need to add an <access> tag for your web service:

<access origin="http://janasenanews.com" />

or to allow all requests:

<access origin="*" />

On Android, you'll also need to add a Content Security Policy (CSP) to your index.html:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' janasenanews.com">

More info on all of this is here: https://github.com/apache/cordova-plugin-whitelist

Mike Dailor
  • 1,226
  • 8
  • 16