-1

I m try to write ajax get by using jquery in jsp file. But it always gave error message. I could`nt find the error in my method.

This is my ajax function. Please help me.

<script type="text/javascript">
$.ajax({
    url: "http://crowderia.cloudapp.net/ichainwsDev/api/rest/json/product.list",
    type: "GET",
    data: '{"partyid":4}',
    contentType: 'application/json; charset=UTF-8',
    dataType: 'json',
    success: function(msg){
        alert("success : "+data);
    },
    error:function(msg){
      alert("failure");
    }
});

</script>

Error is : XML HttpRequest cannot load http://crowderia.cloudapp.net/ichainwsDev/api/rest/json/product.list. No 'Access-Control-Allow-Orgin' header is present on the requested resource. Orgin 'http:// localhost:4040' is therefore not allowed access

user2901979
  • 239
  • 2
  • 6
  • 13
  • `contentType: 'application/json; charset=UTF-8'` makes *no* sense at all for a GET request. There is no request body to specify the content type of! – Quentin Feb 13 '14 at 11:59

1 Answers1

1

Try your data

data: {"partyid":4},

in place of

data: '{"partyid":4}',

And try your success callback like,

success: function(msg){
    alert("success : "+msg);// use msg not data
},

Full Code

$(function(){    
    $.ajax({
        url: "http://crowderia.cloudapp.net/ichainwsDev/api/rest/json/product.list",
        type: "GET",
        data: {"partyid":4},
        contentType: 'application/json; charset=UTF-8',
        dataType: 'json',
        success: function(msg){
            alert("success : "+msg);
        },
        error:function(msg){
          alert("failure");
        }
    });
});

You cloud app url works

Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106