0

I am new to jquery. I cannot access java based web services by making ajax call.

My code for ajax call is something like this :

$.ajax({
        type: "POST",
        url: url,
        data: parameters,
        contentType: 'application/json; charset=utf-8',
        dataType:"json",
        headers: {
                Accept: "application/json",
                "Access-Control-Allow-Origin": "*"
        },
        success: function(data, textStatus, jqXHR) {
          alert('Success');
        },  
        error: function(jqXHR, textStatus, errorThrown){
          alert('Failure');
        }
});

I am getting error : XMLHttpRequest cannot load "server url. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

Web service response while accessing via rest client on browser is something lie this : Status Code: 200 OK Content-Type: application/json Date: Wed, 03 Sep 2014 09:42:32 GMT Server: Apache-Coyote/1.1 Transfer-Encoding: chunke " Any help is greatly appreciated Thanks in advance

Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106
user2814546
  • 107
  • 8

2 Answers2

0

You trying to access different domain data.

So replace with dataType:"jsonp" instead ofdataType:"json",

Raja Sekar
  • 2,062
  • 16
  • 23
0

the Header

 "Access-Control-Allow-Origin": "*"

must be delivered by the server

http://enable-cors.org/server.html

john Smith
  • 17,409
  • 11
  • 76
  • 117