admin管理员组

文章数量:1323714

I am trying to load a page within another page using jquery load() function. Below is the code:

    ... head code
    </head>
    <body id="body">
    <div id="newbody"></div>

    <button id="loadit">loadpage</button>
    <script type="text/javascript">
    $("#loadit").click(function(){
        $( "#newbody" ).load( "edit.php?id=112" );

        }); 
    </script>

When I click the button the whole page is cleared and only a single bit of the "edit.php" page is displayed. By single bit I mean that edit.php is supposed to display a prepopulated form and only a single field is displayed with no CSS whatsoever. Is it because I am using the wrong jQuery function i.e. load(). What I want to do is load a new page in a div tag within the current page.

I also get the following warning in the console:

jquery.min.js:4 Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.

Where am I going wrong?

I am trying to load a page within another page using jquery load() function. Below is the code:

    ... head code
    </head>
    <body id="body">
    <div id="newbody"></div>

    <button id="loadit">loadpage</button>
    <script type="text/javascript">
    $("#loadit").click(function(){
        $( "#newbody" ).load( "edit.php?id=112" );

        }); 
    </script>

When I click the button the whole page is cleared and only a single bit of the "edit.php" page is displayed. By single bit I mean that edit.php is supposed to display a prepopulated form and only a single field is displayed with no CSS whatsoever. Is it because I am using the wrong jQuery function i.e. load(). What I want to do is load a new page in a div tag within the current page.

I also get the following warning in the console:

jquery.min.js:4 Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.

Where am I going wrong?

Share Improve this question edited Oct 26, 2016 at 16:47 Arihant asked Oct 26, 2016 at 16:45 ArihantArihant 4,04718 gold badges59 silver badges91 bronze badges 5
  • Are you getting any errors at all, either in your console, or on the actual edit.php page? – MCMXCII Commented Oct 26, 2016 at 16:47
  • @MCMXCII just edited with the warning in console. edit.php, as a separate page works totally fine – Arihant Commented Oct 26, 2016 at 16:48
  • Have you tried using the .ajax() function instead of .load()? – MCMXCII Commented Oct 26, 2016 at 16:50
  • 2 @sabithpocker, it's async: false actually. But it looks like it's only a warning and not the root cause of the problem. – Frédéric Hamidi Commented Oct 26, 2016 at 16:51
  • @sabithpocker - I think the data is being called but the whole page is being changed. any thoughts on that? – Arihant Commented Oct 26, 2016 at 17:00
Add a ment  | 

1 Answer 1

Reset to default 8

You may get this warning in case edit.php contains a script tag within it that loads an external javascript file e.g.

<div> 
SOME CONTENT HERE
</div>
<script src="/scripts/script.js"></script> 

Just to note that this is from this stackoverflow answer - https://stackoverflow./a/28478146/3274227

本文标签: javascriptjQuery load() errorSynchronous XMLHttpRequest on the main thread is deprecatedStack Overflow