Cannot Obtain the Response Message of a jQuery AJAX call (JSON request)

In the attached piece of AJAX call through JSON request, I get an alert message saying "Status: success" but cannot get the response message somehow. We are inclined to use the Webservice call request with PHP and AJAX.

However, we do get the response text if tried through RESTClient or POSTER, attached an example screenshot.

Could someone please help?
<script type="text/javascript" src="/scripts/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
    type: 'POST',
    url: '',
    dataType: 'json',
    contentType: 'application/json; charset=utf-8',
    data: '{"authorizationToken":"xyz=","purchaseKey":"testmsg", "identifier":"1","purchaseType":"2"}',
    success: function(data, resultState) {
        if (!resultState) {
            alert('No result found!');
        } else {
            alert('Status: ' + resultState);
    error: function(xhr) {
    complete:function() {

Open in new window

LVL 32
Who is Participating?
jjperezaguinagaConnect With a Mentor Commented:
Greetings ldbkutty,

Please feel free to research about CORS (Cross-Origin Resource Sharing) and XML HTTP Request Level 2. This is already a W3C working draft.

Unluckily, XML HttpRequest Level 2 is still not supported as part of the jquery library so you would need to do some code by yourself. However, I think for this case, giving a quick read to CORS will be enough to solve your problem.

Best regards,

Ivo StoykovCommented:
check what type of response is returned - xml, html, json...
Gurvinder Pal SinghCommented:
can you share the output of alert(data); in the else section of success handler?

How did you know if you are not getting the response?
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

ldbkuttyAuthor Commented:
With Chrome firebug console, got this error message...

XMLHttpRequest cannot load http://site_name:8095/ECMWebService/purchase/markPurchase. Origin is not allowed by Access-Control-Allow-Origin.

May be the server is thinking that am trying to hack the server through cross-site scripting.

If the site_name can whitelist our "xyz" domain in the Access-Control-Allow-Origin setting of web-server, will it be good? I am exploring the Access-Control-Allow-Origin property right now ....
You need to use a proxy, cross domain ajax call is not allowed for security purpose, for example this one :
ldbkuttyAuthor Commented:
the proxy was a great idea, but it also results in the following error:

Failed to load resource: the server responded with a status of 405 (Method Not Allowed) proxy.php?
the proxy_url is a full url (encoded with encodeURIComponent :  http:
    type: 'POST',
    url: 'proxy.php?proxy_url=' + encodeURIComponent( "" ),

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.