开发者

JQuery Load Page Content into Div

开发者 https://www.devze.com 2023-03-19 14:27 出处:网络
I found lots of questions/answers regarding how to load page content into a div; however, I can\'t get mine to load.I am running the jquery inside document.ready.Running an alert by itself works fine,

I found lots of questions/answers regarding how to load page content into a div; however, I can't get mine to load. I am running the jquery inside document.ready. Running an alert by itself works fine, but the code below does not. Any pointers would be greatly appreciated. Thanks!

//First I tried this:
$("#divTestPreview").load("~/Testing/TestCreation/AddTes开发者_如何转开发tItems.aspx");
//and then I tried this:
$.get('~/Testing/TestCreation/AddTestItems.aspx', function (data) {
            $('#divTestPreview').html(data);
            alert('Load was performed.');
});

<div id="divTestPreview" runat="server" style="width: 100%; height: 500px;">
</div>


Try removing the runat="server" in your div as I think your ASP.NET interpreter might be fiddling with the HTML before it reaches the client.

Thanks!


your div has runat="server" tag which makes it a server side control. To access it in client side you need to use ClientID to access the div. Like this

$("#<% divTestPreview.ClientID %>").load();


you can use load and get to load only pages inside your domain other wise you will get cross domain error there is a solution for it you need to create some sort of proxy read this: WebBrowser Control: Disable Cross Site XSS Filtering or another way to process JS in full on HTML or you can try this: http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/


That is not allowed by Access-Control-Allow-Origin, you are making cross domain AJAX, and it's no possible in current versions browsers, you have to do it in the server side, for example in PHP with fopen() o file_get_contents(), if you need to make it on client side, there are many options like flensed FLXHR or CORS for modern browsers.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号