I'm still experimenting with a new citysearch module. I've managed to fetch back the json with curl but I'd still like to let ajax handle it. I have this function but it reports a 404 error. Is there a way to determine the url value actually being sent? The generated value I'm using here works both with window open() and with my curl function. My code:
function processSearch(form) { var what = js_trim(form.what.value); var where = js_trim(form.where.value); var loc = js_trim(form.location_or_event.value); var publisher = js_trim(form.publisher.value); var api_key = js_trim(form.api_key.value);
var URL = 'api2.citysearch.com/search/'+loc+'?what='+what +'&where='+where+'&format=json&publisher='+publisher +'&api_key='+api_key;
alert(URL); $.ajax({ type: 'get', url: URL, dataType: 'jsonp', success: function() { alert("Some success"); }, error:function (xhr, ajaxOptions, thrownError){ alert(xhr.status); alert(xhr.statusText); alert(xhr.responseText); } }); // end ajax method }
function js_trim(str) { return str.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); }
Scott,
Using firebug in Firefox will let you see exactly what goes back and forth in an ajax request.
However, below will not work because, as a security feature, ajax requests can only be sent to the same domain that the page originated from. Ie, if your site is example.com, then ajax GETs and PUTs can only be performed back to example.com, not to other sites directly from the client browser such as api2.citysearch.com.
What you need to do is make a server side wrapper. Your ajax call should be back to your own site, example.com, which can then take the request and with PHP build a curl request to api2.citysearch.com. Once your server has received the response from citysearch, then it can deliver it as the reply to the original ajax request.
Seth
Scott wrote:
I'm still experimenting with a new citysearch module. I've managed to fetch back the json with curl but I'd still like to let ajax handle it. I have this function but it reports a 404 error. Is there a way to determine the url value actually being sent? The generated value I'm using here works both with window open() and with my curl function. My code:
function processSearch(form) { var what = js_trim(form.what.value); var where = js_trim(form.where.value); var loc = js_trim(form.location_or_event.value); var publisher = js_trim(form.publisher.value); var api_key = js_trim(form.api_key.value);
var URL = 'api2.citysearch.com/search/'+loc+'?what='+what +'&where='+where+'&format=json&publisher='+publisher +'&api_key='+api_key;
alert(URL); $.ajax({ type: 'get', url: URL, dataType: 'jsonp', success: function() { alert("Some success"); }, error:function (xhr, ajaxOptions, thrownError){ alert(xhr.status); alert(xhr.statusText); alert(xhr.responseText); } }); // end ajax method }
function js_trim(str) { return str.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); }
Did you look in your (watchdog)logs? Normally the 404's received by a drupal sites are logged there with the full path.
Dave
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Scott Sent: Friday, May 21, 2010 2:19 PM To: Drupal Support Subject: [support] jQuery.ajax returns 404
I'm still experimenting with a new citysearch module. I've managed to fetch back the json with curl but I'd still like to let ajax handle it. I have this function but it reports a 404 error. Is there a way to determine the url value actually being sent? The generated value I'm using here works both with window open() and with my curl function. My code:
function processSearch(form) { var what = js_trim(form.what.value); var where = js_trim(form.where.value); var loc = js_trim(form.location_or_event.value); var publisher = js_trim(form.publisher.value); var api_key = js_trim(form.api_key.value);
var URL = 'api2.citysearch.com/search/'+loc+'?what='+what +'&where='+where+'&format=json&publisher='+publisher +'&api_key='+api_key;
alert(URL); $.ajax({ type: 'get', url: URL, dataType: 'jsonp', success: function() { alert("Some success"); }, error:function (xhr, ajaxOptions, thrownError){ alert(xhr.status); alert(xhr.statusText); alert(xhr.responseText); } }); // end ajax method }
function js_trim(str) { return str.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); }
-- [ Drupal support list | http://lists.drupal.org/ ]
Again I'm struck with the obvious solution, check the logs. It would seem that the ajax function is appending the supplied url to my local domain name (my development box) so of course it must return a 404.
On Fri, 2010-05-21 at 15:57 -0700, Metzler, David wrote:
Did you look in your (watchdog)logs? Normally the 404's received by a drupal sites are logged there with the full path.
Dave