I'm trying to develop a drupal module to return json from the citysearch api. I can successfully construct the url and I can use the url to open a new window and display the returned json data, thus:

testwindow= window.open (URL, "mywindow",
    "location=1,status=1,scrollbars=1,width=100,height=100");

however, my attempt to try this with ajax fails, thus:

$.ajax({
 type: 'get',
 url: URL,
 dataType: 'jsonp',
 error: function() { alert("Some error"); },
 success: function() { alert("Some success"); }
}); // end ajax method

This always results in the "Some error" alert. I've tried it with 'get' and 'post' for type and with 'json' and 'jsonp' for dataType. No joy. I would appreciate any thoughts on what fundamental points I'm missing here.

When the URL is in another domain the underlying XMLHttpRequest will never succeed in some browsers and in others it may be blocked by security settings.

So, what is the secret? How can I read the results of a call to the api, xml or json, into an object? window.open displays the raw json object but does not provide much functionality and if the call fails for some reason it does not report error codes that may be returned. Also, I don't particularly want the results to be displayed in a pop-up window. I get the same 400 error using curl.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.