简体   繁体   English

页面无法执行$(“#..”)。load()

[英]Page Unable to execute a $(“#..”).load()

Functionality: 功能:

When Users tap on an image button, it is suppose to bring the user from the current page to the next page. 当用户点击图像按钮时,可以将用户从当前页面转到下一页。

What has been done: 已经做了什么:

I have made use of jQuery method call: .load(url) , hence the syntax will look something like : $("#divID").load("***.html"); 我已经使用了jQuery方法调用: .load(url) ,因此语法看起来像: $("#divID").load("***.html");

Issue: 问题:

When I clicked on the image button, it gives the following error msg: 当我单击图像按钮时,它给出以下错误消息:

XMLHttpRequest cannot load XMLHttpRequest无法加载
jquery-1.11.3.min.js:5 file:///Users/trinax/Documents/Ernest/Project/ToysRUs/ToyRUs(main)/TapAStar.html. jquery-1.11.3.min.js:5文件:/// Users / trinax / Documents / Ernest / Project / ToysRUs / ToyRUs(main)/TapAStar.html。 Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource. 跨源请求仅支持以下协议方案:http,数据,chrome,chrome扩展名,https,chrome-extension-resource。

and furthermore, the resultant page is blank and doesn't display anything. 而且,结果页面为空白,不显示任何内容。

what has gone wrong?please help 出了什么问题?请帮忙

 $("#tapButton").click(function() { // Enter Link here (Tap A Star Game) $("#load_tapGame").load("Tap.html"); $("#menu").fadeOut(function() { $("#load_tapGame").fadeIn(); }) }) 
 <div id="load_tapGame"></div> <div id="menu"> <img style="position: absolute; top: 2150px; left: 185px; z-index: 2" src="library/image/tapAStarButtonCloud.png" /> <div class="button"> <button id="tapButton" class="buttonProperty"> <img src="library/image/tapButton.png" /> </button> </div> </div> 

You need to use a server. 您需要使用服务器。 Trying to load things using javascript when working locally will fail due to CORS. 由于CORS,在本地工作时尝试使用javascript加载内容的操作将失败。 https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Access_control_CORS

I like to use Live Server for local testing. 我喜欢使用Live Server进行本地测试。 You can find instructions on how to install it using npm here: https://github.com/tapio/live-server 您可以在此处找到有关如何使用npm进行安装的说明: https : //github.com/tapio/live-server

You can find instruction on installing npm (Node Package Manager) here: https://nodejs.org/en/download/ 您可以在以下位置找到有关安装npm(节点软件包管理器)的说明: https : //nodejs.org/en/download/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM