admin管理员组文章数量:1302267
I have a Cocoa WebView that displays a local HTML file. I'm trying use jQuery.load() to load another local HTML file into a div. My JavaScript code goes something like this:
$("#mydiv").load("test.html"); // test.html is a local file inside the app's bundle
I don't see any exceptions but it will not load the html inside the div. I'm using exactly the same code for an iOS app, and it works fine. I've also tried using XMLHttpRequest() and I can see the responseText fine.
Any advice? Thanks in advance!
I have a Cocoa WebView that displays a local HTML file. I'm trying use jQuery.load() to load another local HTML file into a div. My JavaScript code goes something like this:
$("#mydiv").load("test.html"); // test.html is a local file inside the app's bundle
I don't see any exceptions but it will not load the html inside the div. I'm using exactly the same code for an iOS app, and it works fine. I've also tried using XMLHttpRequest() and I can see the responseText fine.
Any advice? Thanks in advance!
Share Improve this question asked Jul 17, 2013 at 23:47 ReinaldoReinaldo 4,6763 gold badges26 silver badges24 bronze badges 2-
You could try putting a
$(document).ready
before the.load()
to ensure the page is fully there before trying to load something new into it. Depending on load time I've had JS fail due to the targetted div not being there when it's trying to execute. – Peter Oram Commented Jul 17, 2013 at 23:53 - Actually the code is being executed after the DOM has loaded. I'm thinking is something related to Cocoa's WebView as the same code runs without issues under iOS, Android and Windows. Thanks for the time. – Reinaldo Commented Jul 18, 2013 at 0:04
3 Answers
Reset to default 3A nice little work around just replace home.html with your local html file and content with your div id
document.getElementById("content").innerHTML='<object type="text/html" data="home.html" ></object>';
works in Chrome, Firefox, and IE enjoy!
I was able to get around the problem by using jQuery.ajax instead. Here's how I did it:
jQuery.ajax({
url: "test.html", dataType: "html"
}).done(function( responseHtml ) {
$("#mydiv").html(responseHtml);
});
Hope it helps someone!
var $div = $('div#something');
$div.load("test.html");
本文标签: javascriptjQuery load is not loading a local html file inside a Cocoa WebViewStack Overflow
版权声明:本文标题:javascript - jQuery .load is not loading a local html file inside a Cocoa WebView - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741691076a2392724.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论