1

Here is my jQuery ajax code

      $.ajax({
    type: "GET",
    url: "http://example.com/request=r",
    dataType: "json",
    processData: true,
    data: {},
    success: function (responseString) {
        alert(responseString);
    },
    error: function (xhr, errorType, exception) {
        var errorMessage = exception || xhr.statusText;
        alert("Excep:: "+exception +"Status:: "+xhr.statusText);
    }
});

I don't get an exception but I get xhr.statusText as Error

6
  • did you load the script from the domain to which you make the ajax request? Commented Jan 10, 2013 at 15:04
  • not its hosted in another domain Commented Jan 10, 2013 at 15:05
  • 2
    thats your problem; its a same-origin-policy issue Commented Jan 10, 2013 at 15:06
  • What does the alert say? Commented Jan 10, 2013 at 15:07
  • Do you own cs-api-sandbox and/or does it support JSONP? Commented Jan 10, 2013 at 15:07

1 Answer 1

2

You're falling foul of the Same Origin Policy. The only client-side alternative is to use JSONP request type, if the provider supports it.

If not you'll need to write a server-side proxy to get the data (in PHP/C# etc) and then query that via AJAX instead.

Sign up to request clarification or add additional context in comments.

4 Comments

@jade by server-side I mean on your own site. You then make an AJAX request to the local page which has grabbed the external data.
how do i do dat?i mean how to get data from that url without before using Ajax
Does your server support PHP/ASP/Python?
I don't know python, but if you google for how to make an external request I'm sure you'll find something.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.