jQuery AJAX 在第一个 PHP 条件后不显示输出
我在使用 jQuery AJAX 调用时遇到问题。查询运行正常,调试输出也显示正确的数据,但除了被调用文档中的第一个 PHP 条件之外的任何内容都不会显示。
首先,有两个按钮,一个链接到“core”,另一个链接到“email”:
这是相关的 JavaScript:
$("#core").click(function(){
loaddetails ("core");
});
$("#email").click(function(){
loaddetails ("email");
});
function loaddetails(type) { var query = "details=" + type;
$.post("details.php", query , function( data ) {
$("#d-features").html(data); alert (data);});
return false;
};
以及details.php 的内容:
<? if($_POST['details']=='core'){ ?> blah1 <? }
if($_POST['details']=='email') { ?> blah2 <? } ?>
“blah1”和“blah2”都出现在警报框调试输出中。但是,只有“blah1”会发布在页面 div (#d-features) 上,因为“blah2”永远不会出现在页面上。
我检查了Firebug,绝对没有错误。但我怀疑第二个条件请求可能已经循环,因为单击“电子邮件”按钮时显示的警报窗口显示“阻止页面创建其他对话框”,尽管即使未选中也不会显示任何其他对话框。
是什么导致了这个问题以及如何解决它?
I am having trouble using the jQuery AJAX call. The query runs properly and debug output also shows the correct data, but anything apart from the first PHP conditional in the document being called is not being shown.
First, there are two buttons, one linked to "core" the other "email":
Here's the relevant JavaScript:
$("#core").click(function(){
loaddetails ("core");
});
$("#email").click(function(){
loaddetails ("email");
});
function loaddetails(type) { var query = "details=" + type;
$.post("details.php", query , function( data ) {
$("#d-features").html(data); alert (data);});
return false;
};
And the contents of details.php:
<? if($_POST['details']=='core'){ ?> blah1 <? }
if($_POST['details']=='email') { ?> blah2 <? } ?>
Both "blah1" and "blah2" appear in the alert box debug output. But, only "blah1" ever gets posted on the page div (#d-features), as "blah2" never appears on the page.
I have checked Firebug and there are absolutely no errors. But I suspect the second conditional request may have gone in a loop, as the alert window showing up when "email" button is clicked shows "Prevent page from creating additional dialogs", though no additional dialogs show up even when unchecked.
What is causing this problem and how to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
.html() 替换内容而不是附加内容。
尝试更改该行以查看两次调用是否返回所有数据:
$("#d-features").html(data);
==>$("#d-features").append(data);
.html() replaces the content instead of appending.
Try changing that line to see if all the data is returned from both calls:
$("#d-features").html(data);
==>$("#d-features").append(data);
对您的代码进行一个小修改,您可以尝试看看这是否有效:
A small modification on your code, you could try to see if this works:
好的,这似乎与我为包含这些链接的 div 加载的选项卡效果发生冲突。因此,一旦我删除了该效果,它现在就起作用了。但我还不确定效果有什么问题,我会发布另一个问题来弄清楚。
感谢那些提供帮助的人!
Ok, it seems to be a conflict with the tabs effect I loaded for a div that encompassed these links. So once I removed that effect, it works now. But I'm not sure what is wrong with the effect yet, I'll post another question to figure it out.
Thanks to those that offered assistance!