[英]Loading part of HTML from another file using JQuery in JSP page gives 404 Not Found error
I have used JQuery to load the small part of my JSP page but I am getting 404 Not Found error . 我已经使用JQuery加载了我的JSP页面的一小部分,但出现404 Not Found错误 。 I have placed the home.jsp with sample.jsp . 我已经将home.jsp与sample.jsp一起放置了。 I have written a html form in sample.jsp file and have loaded the same file to a div in home.jsp using load() method of JQuery. 我已经在sample.jsp文件中编写了一个html表单,并使用JQuery的load()方法将同一文件加载到了home.jsp中的div中。
<div id="app"></div> <script type="text/javascript"> $(function() { $( "#app" ).load( "templates/form-signin.html" ); }); </script>
Check the URL which gives you 404 in the network tab of your browser's developer options. 在浏览器开发人员选项的网络标签中,检查为您提供404的URL。 Then check if you can open it manually. 然后检查是否可以手动打开它。 You'll probably get a 404 this way too. 您也可能会以这种方式获得404。 Make sure the file is accessible on that URL and adjust the location/server settings/url accordingly. 确保可以在该URL上访问该文件,并相应地调整位置/服务器设置/ URL。
Ok, I solved it. 好的,我解决了。 Instead of a JQuery load() call, I have created an API that serve that sample.jsp file with a HTML form inside the div of home.jsp. 我没有创建JQuery load()调用,而是创建了一个API,用于在home.jsp的div内以HTML形式为该sample.jsp文件提供服务。
<div id="app"></div> <script type="text/javascript"> $(function() { $( "#app" ).empty(); $.ajax({ type: "GET", url: "http://localhost:8080/appname/loginform", cache: false, success: function(data){ $("#app").append(data); } }); }); </script>
Thank you all for your help. 谢谢大家的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.