I am developing a module which has a jQuery script with some AJAX code. The ajax code calls a php script located in the same location as the jQuery script.
My problem is, AJAX appends the domain name in front of the PHP script name and of course, my script does not exist at that location and so the process breaks.
The AJAX code is as follows:
$(document).ready(
function(){
$.ajax({
url: "/testscript.core.php",
asych: false,
success: function($data){
$('textarea#edit-simplechat-messages').text( $data );
}
});
}
);
And the following is the link that shows up in firebug:
http://testsite.co.uk/testscript.core.php
Again, the jQuery script and the php script are in the same directory. I thought the forward slash before my php script name would eliminate the domain name but it did not work.
the way it is now it looks like your problem is the slash before the file name.. that means "domain web root"
Use
This link might be useful
http://www.akchauhan.com/how-know-base-path-of-drupal-in-javascript/
EDIT :
Or you can use this approach if you are creating your own custom module then follow these steps
1] First create your module, Here my module name is "mymodule", So i created a file name mymodule.module
2] Secondly create js file with the same name so name it mymodule.js under the same module file.
Notice in js file i have used mypath. your js file will call this path which is defined in the hook_menu().