[support] calling url from javascript

Christopher M. Jones cjones at partialflow.com
Mon Nov 22 19:30:55 UTC 2010


So your ajax call is sending exactly what you tell it to send.

If you send '?q=mycallback' then it sends that, relative to the current 
URL (e.g., http://mysite.com/some/path/?mycallback).

If you don't include the q= as in '/mycallback' then it sends that-- 
relative to the current url (e.g., http//mysite.com/some/path/mycallback).

If you want to be safe, then just always send the "q=" version. Drupal 
understands it, even if clean urls are enabled. If you want your ajax 
request to respect the site's settings, then send the request without 
the q=, and test for a valid response. If no valid response then try the 
non-q= version of the url.

But this seems a little silly, since most users don't monitor ajax 
requests in firebug as they're browsing the web. Or if they do then I 
shouldn't imagine they would care whether there's a q= in there or not.


On 11/22/2010 01:53 PM, Christopher M. Jones wrote:
> Have a look at the Drupal.settings object. Of interest to you is the
> basePath property.
>
> On 11/22/2010 01:39 PM, Aldo Martinez Selleras wrote:
>> how I can write my code for the URL written in JavaScript are from the root
>> of the site and are independent of whether they are clean URL enabled or
>> not?
>>
>> If y write this
>>
>> $.get('?q=mycallback', function(data){
>> })
>>
>> The code sends this
>>
>> http://mysite.domain.com/current_url?q=mycallback
>>
>> I have enabled the Clean URL, if I disable this option, then
>>
>> If y write this
>>
>> $.get('/mycallback', function(data){
>> })
>>
>> The code sends this
>>
>> http://mysite.domain.com/mycallaback
>>
>> some suggest?
>>
>>


More information about the support mailing list