Jquery发布回调函数不起作用

时间:2022-12-08 19:48:25

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

我无法让我的回调函数在post中工作:

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

我在点击功能中得到了这个。我已经尝试了$()。click(function(e){..}和$()。livequery('click',function(e){。

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

test.php:

test.php的:

echo "bah";

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

Firebug说返回值是“bah”,请求处理好了。

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

我已经通过*搜索了类似的问题,但他们没有任何帮助,谷歌和docs.jquery.com没有得到任何更明智的。

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

起初我试图在$()内动态编辑内容。点击使用:$(“#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.

编辑:我修好了。我从我的php文件中发送了一个xml标题(我实际上使用的框架将很多php文件中的内容分开,这使得我的问题有点不好 - 抱歉)然后输出的文本格式不正确。

Thanks for the quick response though :)

谢谢你的快速反应:)

1 个解决方案

#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).

使用Firebug或TamperData确保HTTP请求成功完成。如果它(并且我猜你写的那样),那么请确保该请求实际上是因为Ajax调用而发生的(例如,而不是来自浏览器的简单提交表单)。

#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).

使用Firebug或TamperData确保HTTP请求成功完成。如果它(并且我猜你写的那样),那么请确保该请求实际上是因为Ajax调用而发生的(例如,而不是来自浏览器的简单提交表单)。