简体   繁体   English

使用ajax调用调用aspx页面时未调用Javascript函数

[英]Javascript function not called when aspx page is called using ajax call

I am dynamically loading user control .ascx file in .aspx page using LoadControl. 我正在使用LoadControl在.aspx页中动态加载用户控件.ascx文件。 In .ascx page I am making ajax call and calling an .aspx page. 在.ascx页面中,我正在进行ajax调用并正在调用.aspx页面。 Sample code is as follows 示例代码如下

$(document).ready(function () {

("#TestDiv").load("TestPage.aspx", function (response, status, xhr) {

    if (status == "error")
    {
         //some code
    }
    else
    {
         //some code
    }
}

}); });

In TestPage.aspx I want to call 1 javascript code on its page load. 在TestPage.aspx中,我想在其页面加载时调用1个javascript代码。 I have written javscript alert in document.ready function in TestPage.aspx Following is the sample code 我在TestPage.aspx的document.ready函数中编写了javscript警报,以下是示例代码

$(document).ready(function () {
    alert("Hi");
});

But this javscript alert is not getting called. 但是,此javscript警报未得到调用。 Please let me know what is the issue with this javascript code in TestPage.aspx page. 请让我知道TestPage.aspx页中此javascript代码的问题。

Any help would be greatly appreciated. 任何帮助将不胜感激。 Thanks in advance. 提前致谢。

Regards, Rahul Rathi 此致Rahul Rathi

you have a syntax error, a missing ); 您有语法错误,缺少); You're also missing the $ before ("#TestDiv") 您还缺少$((#TestDiv“)

$(document).ready(function () {
$("#TestDiv").load("TestPage.aspx", function (response, status, xhr) {

    if (status == "error")
    {
         //some code
    }
    else
    {
         //some code
    }
});
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM