post a json to a restful web service from html file

88 Views Asked by At

I am trying to post a json to a restful web service from html file and it is showing "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource"

Code Sniplet from html ajax function:

    var serviceurl="http://192.168.0.100:8080/login";
    var data = {'emailId':'foo','password':'dog'};

     $.ajax({
      url: serviceurl,
      type: 'GET',
      contentType:'application/json',
      data: JSON.stringify(data),
      dataType:'json',
      crossDomain: true,
    xhrFields: {
                   withCredentials: true
               },
      success: function(data){
        //On ajax success do this
      alert(data);
     }});
1

There are 1 best solutions below

1
On

Do you know the The Same Origin Policy? https://en.wikipedia.org/wiki/Same-origin_policy. Should you call serviceurl from your server and redirect the response to the client? Should you use a iframe for do the ajax call? should you use a browser started without the S.O.P.( for chrome :"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --args --disable-web-security)? Please give more information and where you can put your hands :-)