Using jQuery $.ajax() on my site won't work This is the first time for me to use the jQuery $.ajax() in Drupal. The code is a simple test code but it keeps going to the error: section instead of success:. Could my url path be wrong? The .js file and the test-ajax.php file are in the same folder named "code".

    //This is Javascript
    $.ajax({
        url: 'code/test-ajax.php',
        data: 'a=hello&amp;b=world',
        type: 'POST',
        success: function(data){
            alert(data); //Should return "hello, world"
        },
        error: function(){
            alert('FAIL'); //Keep getting "FAIL". It's like it can't find the php file.
        }
    });


Nothing fancy inside the file test-ajax.php:

&lt;?php
$a = $_POST['a'];
$b = $_POST['b'];

echo "$a, $b";
?&gt;


EDIT: To avoid confusion on the paths (I keep it organized):


Main theme files: &lt;templatename&gt;/&lt;.info, template.php, style.css, etc.&gt;
Template files: &lt;templatename&gt;/templates/*.tpl.php
AJAX files: &lt;templatename&gt;/code/&lt;PHP and .JS files&gt;
In Drupal, JavaScript files are added via the drupal_add_js() function or in the
theme’s .info file. 
A simple example of using jQuery in drupal is

    &lt;?php
    drupal_add_js('jQuery(document).ready(function () {
   jQuery.ajax({
        url: '/code/test-ajax.php',
        data: {'a':'hello','b':'world'},
        type: 'POST',
        success: function(data){
            alert(data); //Should return "hello, world"
        },
        error: function(jqXHR, textStatus, errorThrown){
            alert(textStatus + errorThrown); //Better diagnostics
        }
    });
    });', 'inline');
    ?&gt;


you have to use 'jQuery' instead of $.