Wednesday, October 29, 2008

[jQuery] jQuery POSTing to Itself

I have a button that, when clicked, POSTs to a PHP document. Right now
I'm just interested in knowing the PHP is called at all, so I just
have it call a dummy INSERT statement as evidence it worked.

$(document).ready(function()
{
$('.modalSave').click(function()
{
var id = GetIDNumber(this.id); // all of my IDs are in the form
[className]_[ID #]
var myStr = 'helloworld';

$.post('backend.php', { param1: myStr, param2: id },
function(data) { alert(data); });
});
});

function GetIDNumber(id_str)
{
return id_str.match(/\d+$/);
}
});

(end code)

When this code is tested, the Firebug response is 200 OK. It's clearly
not looking for backend.php, though: the contents of alert() is the
HTML of the entire page containing the call. If I rename backend.php
to something else, Firebug still reports 200 OK.

What the heck is jQuery up to, POSTing to itself?

No comments: