Ajax - 返回html页面 - 关于该页面的加载功能未执行

时间:2016-03-28 09:33:15

标签: javascript jquery html ajax

我有一个ajax调用,返回整个html页面。

现在html页面有一个在页面加载事件上执行的函数。

但是当我通过ajax调用它时它没有执行但是当我通过浏览器调用它时它正在执行。

例如,

在浏览器www.abc.com/test/test1(加载时加载jquery功能)

在ajax中调用www.abc.com/test/test1(不加载jquery函数)

我想通过ajax调用来执行该函数。

Ajax调用

function test(str)
        {
            var $ajaxJQuery = jQuery.noConflict();
            console.log("insidee test");
            console.log(str);
            var $ajaxJQuery = jQuery.noConflict();          
             $ajaxJQuery.ajax({
                type:'GET',
                url: "http://www.test.com/test/test-1",
                success: function(data){
                    console.log(data);

                    //$ajaxJQuery("#Micrositecontainer").html(data);
                    $ajaxJQuery('body').html(data);     
                    //window.location = str;
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert("err");
                    top.location = '${appBaseUrl}/'+responseUrl;
                }
            });
        }

以下是html页面:=

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="shortcut icon" href="images/general/favicon.ico" type="image/x-icon">

<title>Test 1</title>

<script>

            var $j = jQuery.noConflict();
            var locationDialogOpenFirstTime = true;
            var isTextChange = false;
            var inValidResult = 0;


            function getAllComponent(){
                    //  getCKHeaderdata();

                    var hideLocSession=''
                    if(hideLocSession=='Edit')
                    {
                        if(document.getElementById('hideLocation')!= null)
                            document.getElementById('hideLocation').className='usernameActive';
                    }
                    else if(hideLocSession=='Hide'){
                        if(document.getElementById('hideLocation')!= null)
                            document.getElementById('hideLocation').className='';
                    }
                    if(hideLocSession != null && hideLocSession!='' && hideLocSession != ' ' && hideLocSession != 'null' )
                    {
                        if(hideLocSession=='Edit')
                        {
                            $j("#showhideheader").toggle();
                            $j("#showhideTopNav").toggle();
                            $j("#showhideleft").toggle();
                            $j("#showhideRight").toggle();
                            $j("#hideshowMiddle").toggle();
                            $j("#showhideFooter").toggle();
                            $j("#sortIcon").toggle();
                        }
                    }


                         drawTreexmlTreeFoldersObj('&frmLeftTree=1');
                        drawTreexmlTreeOrphanObj();
                            getCommentOnload();

            }

</script>
</head>
<body  class="bodyimage bodyimage3 systemheaderBody" onload="getAllComponent()">
// some content is here
</body>
</html>

现在当我通过ajax调用此页面时,getAllComponent()没有加载,但是当我通过浏览器打开此页面时执行

0 个答案:

没有答案