4

I'm having trouble getting my callback function to work in post:

I've got this in a click function. I've tried both $().click(function(e){..} and $().livequery('click', function(e) {.

e.preventDefault();
$.post("test.php", {}, function(data) {
    alert("bang"); //doesn't register
});
alert("bom"); //works fine

test.php:

echo "bah";

Firebug says the return value is "bah" and the request was processed okay.

I've searched through stackoverflow for similar questions but they weren't of any help, google and docs.jquery.com without getting any wiser.

At first I was trying to edit content on the fly inside $().click using: $("#commentbody:first").find(".commentboxnew").prev().

But now even the alert won't work.

Edit: I fixed it. I had sent a an xml header from my php file (I'm actually using a framework which divides stuff in a lot of php files which made my question kinda bad - sorry about that) and then the outputted text was ill-formatted.

Thanks for the quick response though :)

7
  • Is anything odd showing up in the console tab of Firebug? Commented Oct 23, 2009 at 14:04
  • Not that I can see. I just get "POST url 200 OK 595ms". How do you see if it's successful or not? Commented Oct 23, 2009 at 14:06
  • If you get a response and the row doesn't appear in red, I guess Firebug feels it's okay. Commented Oct 23, 2009 at 14:08
  • I'm not sure you need the empty {}, have you tried without them? Commented Oct 23, 2009 at 14:09
  • Yeah, both with and without and I've tried to send different settings too which it accepts. Commented Oct 23, 2009 at 14:11

1 Answer 1

2

Use Firebug or TamperData to make sure that the HTTP request is completing successfully. If it is (and I guess you wrote that it is), then make sure that the request is in fact happening because of that Ajax call (and not from the browser simply submitting a form, for example).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.