jQuery AJAX 在第一个 PHP 条件后不显示输出

发布于 2024-11-27 12:18:32 字数 888 浏览 4 评论 0原文

我在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜妞爱困 2024-12-04 12:18:33

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

五里雾 2024-12-04 12:18:33

对您的代码进行一个小修改,您可以尝试看看这是否有效:

function loaddetails(type) { 
    $.post(
        "details.php", 
        {
            details:    type
        }, 
        function( data ) {
            $("#d-features").html(data); 
             alert (data);
        }
    );
    return false;
}

A small modification on your code, you could try to see if this works:

function loaddetails(type) { 
    $.post(
        "details.php", 
        {
            details:    type
        }, 
        function( data ) {
            $("#d-features").html(data); 
             alert (data);
        }
    );
    return false;
}
冷情 2024-12-04 12:18:33

好的,这似乎与我为包含这些链接的 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文