Reputation: 155
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/AddTestItems.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>
Upvotes: 0
Views: 2591
Reputation: 428
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();
Upvotes: 1
Reputation: 258
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.
Upvotes: 0
Reputation: 5912
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/
Upvotes: 1
Reputation: 91
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!
Upvotes: 2