模式对话框未显示正确的信息

发布于 2025-01-07 20:42:17 字数 1627 浏览 1 评论 0原文

这是我的动作脚本

action.js

function showDistrict() { //alert("hello");
    $.ajax({
        url: 'dialog_applet.jsp#dialog-modal-district',
        success: function(msg) {
            document.getElementById("dialog-content-district").innerHTML = msg;
        }
    });
    $(function() {
        $("#dialog:ui-dialog").dialog("destroy");
        $("#dialog-content-district").dialog({
            height: 300,
            width: 350,
            modal: true
        });
    });
    // alert("hello1");
}

function showCity() { //alert("hello");
    $.ajax({
        url: 'dialog_applet.jsp#dialog-modal-city',
        success: function(msg) {
            document.getElementById("dialog-content-city").innerHTML = msg;
        }
    });
    $(function() {
        $("#dialog:ui-dialog").dialog("destroy");
        $("#dialog-content-city").dialog({
            height: 300,
            width: 350,
            modal: true
        });
    });
    // alert("hello1");
}​

这是我的内容脚本,位于 dialog_applet.jsp 内,

<div id="dialog-modal-district">

dialog-modal-district is here
</div>
<div id="dialog-modal-city">
dialog-modal-city is here
/applet>

调用任何一个函数 showDistrict()showCity()。它显示了

的内容。但是,我想检索已被调用的特定
内容。我的意思是在调用 showDistrict 时,它只会显示 dialog-modal-district is here,但它显示 dialog-modal-district is hereDialog-模态城市在这里

任何帮助表示赞赏! 提前致谢。 !!

this is my action script

action.js

function showDistrict() { //alert("hello");
    $.ajax({
        url: 'dialog_applet.jsp#dialog-modal-district',
        success: function(msg) {
            document.getElementById("dialog-content-district").innerHTML = msg;
        }
    });
    $(function() {
        $("#dialog:ui-dialog").dialog("destroy");
        $("#dialog-content-district").dialog({
            height: 300,
            width: 350,
            modal: true
        });
    });
    // alert("hello1");
}

function showCity() { //alert("hello");
    $.ajax({
        url: 'dialog_applet.jsp#dialog-modal-city',
        success: function(msg) {
            document.getElementById("dialog-content-city").innerHTML = msg;
        }
    });
    $(function() {
        $("#dialog:ui-dialog").dialog("destroy");
        $("#dialog-content-city").dialog({
            height: 300,
            width: 350,
            modal: true
        });
    });
    // alert("hello1");
}​

this is my content script which is inside of dialog_applet.jsp

<div id="dialog-modal-district">

dialog-modal-district is here
</div>
<div id="dialog-modal-city">
dialog-modal-city is here
/applet>

on call of any one function showDistrict() or showCity(). it is showing contents of both <div> . But, i want to retrieve the particular <div> contents, which has been called. I mean on call of showDistrict, it will only show the dialog-modal-district is here, but it is showing dialog-modal-district is here dialog-modal-city is here

Any help appreciated !!
Thanks in advance. !!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

海风掠过北极光 2025-01-14 20:42:17

如果我正确地回答了你的问题,我相信在调用函数 showCity() 时,你将得到 ajax 响应作为两个 div 的内部内容,即
对话框模态区和对话框模态城市。这是因为您只是加载 urldialog_applet.jsp#dialog-modal-city,它将返回dialog_applet.jsp 页面的全部内容,而不仅仅是#dialog-modal-city div 内容。

您可以将 div 名称作为参数与 URL 一起传递,根据传递的 URL,您可以生成 ajax 响应。

If I got your question correctly, I believe on call of function showCity(), you will be getting ajax repsonse as the inner content of both divs, namely,
dialog-modal-district and dialog-modal-city. This is because you are just loading the url dialog_applet.jsp#dialog-modal-city, which will return entire content of dialog_applet.jsp page and not just #dialog-modal-city div content.

You can pass the div name as parameter along with URL, depending upon the URL passed you can generate the ajax response.

累赘 2025-01-14 20:42:17

我现在明白问题所在了。

不幸的是,使用 url dialog_applet.jsp#dialog-modal-district 将完全加载 jsp 页面的内容,而不仅仅是您指定的片段。

您有两种选择来实现您想要的目标。

  1. 提取您想要插入到对话框中的实际内容。 ajax 请求将加载完整的 jsp 页面,使用 .find() 方法您可以选择您感兴趣的部分并将其附加到您的对话框中:

    成功:函数(msg){
        //“msg”是完整的jsp页面
        $(味精)
            //选择你想要的部分
            .find('#dialog-modal-district')
            // 将其附加到您的对话框中
            .appendTo($("#dialog-content-district"));
    }
    
  2. 使用 .load() 来自 jQuery 的方法。它的作用是从指定的 url 加载内容,并允许使用类似于您尝试使用的 url 语法自动加载文档片段:

    $("#dialog-content-district")
        .load('dialog_applet.jsp #dialog-modal-district');
    

    注意jsp页面和ID选择器之间的空白,保留它很重要,否则它将无法工作。

I see now what is the problem.

Unfortunately, using an url dialog_applet.jsp#dialog-modal-district will load completely the content of the jsp page, not only the fragment you specify.

You have two options to achieve what you want.

  1. Extract yourself the actual content you want to insert into the dialogs. The ajax request will load the full jsp page, using the .find() method you can select the part that interests you and only append it to your dialog:

    success: function(msg) {
        // "msg" is the full jsp page
        $(msg)
            // select the part you want
            .find('#dialog-modal-district')
            // append it to your dialog
            .appendTo($("#dialog-content-district"));
    }
    
  2. Use the .load() method from jQuery. Its role is to load content from the specified url and it allows to load document fragments automatically by using a url syntax a little like the one you tried to use:

    $("#dialog-content-district")
        .load('dialog_applet.jsp #dialog-modal-district');
    

    Note the white-space between the jsp page and the ID selector, this is important to keep it, otherwise it won't work.

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