我有可以工作的javascript,但当我更改服务器和链接时,它就不工作了

我有可以工作的javascript,但当我更改服务器和链接时,它就不工作了,javascript,Javascript,如果我是对的,您正在对另一个域执行XMLHttpRequest。因此,浏览器正在阻止它,因为出于安全原因,它通常允许同一来源的请求。当您想要执行跨域请求时,您需要执行一些不同的操作 跨源资源共享(CORS)是W3C规范,允许从浏览器进行跨域通信。通过构建在XMLHttpRequest对象之上,CORS允许开发人员使用与相同域请求相同的习惯用法 你总是可以看到这一点来了解更多。下面给出了CORS样本 XMLHttpRequest cannot load http://gpx1.gdn/countr

如果我是对的,您正在对另一个域执行XMLHttpRequest。因此,浏览器正在阻止它,因为出于安全原因,它通常允许同一来源的请求。当您想要执行跨域请求时,您需要执行一些不同的操作

跨源资源共享(CORS)是W3C规范,允许从浏览器进行跨域通信。通过构建在XMLHttpRequest对象之上,CORS允许开发人员使用与相同域请求相同的习惯用法

你总是可以看到这一点来了解更多。下面给出了CORS样本

XMLHttpRequest cannot load http://gpx1.gdn/country/read. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://gpx2.gdn' is therefore not allowed access.
insertSurveyor:1 XMLHttpRequest cannot load http://gpx1.gdn/province/read. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://gpx2.gdn' is therefore not allowed access.
firebug-lite.js:11883 Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.fetchResource @ firebug-lite.js:11883
firebug-lite.js:30905 Uncaught TypeError: Cannot read property 'push' of undefined(…)

这已经很好地解释了CORS。

您能检查一下您的浏览器控制台中是否有任何错误吗?确保您的URL是正确的。也许您的网站在https上,链接在https上。您确定要检查CORS吗?还将控制台输出共享为@SibeeshVenumentioned@SibeeshVenu我已经签入firebug,脚本已经显示,但是如何在浏览器控制台中检查获取错误?@Faisal在您实现后,如果这篇文章有帮助,请接受作为答案。谢谢你,我终于解决了。。请投票表决我的问题:)
XMLHttpRequest cannot load http://gpx1.gdn/country/read. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://gpx2.gdn' is therefore not allowed access.
insertSurveyor:1 XMLHttpRequest cannot load http://gpx1.gdn/province/read. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://gpx2.gdn' is therefore not allowed access.
firebug-lite.js:11883 Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.fetchResource @ firebug-lite.js:11883
firebug-lite.js:30905 Uncaught TypeError: Cannot read property 'push' of undefined(…)
function createCORSRequest(method, url) {
  var xhr = new XMLHttpRequest();
  if ("withCredentials" in xhr) {

    // Check if the XMLHttpRequest object has a "withCredentials" property.
    // "withCredentials" only exists on XMLHTTPRequest2 objects.
    xhr.open(method, url, true);

  } else if (typeof XDomainRequest != "undefined") {

    // Otherwise, check if XDomainRequest.
    // XDomainRequest only exists in IE, and is IE's way of making CORS requests.
    xhr = new XDomainRequest();
    xhr.open(method, url);

  } else {

    // Otherwise, CORS is not supported by the browser.
    xhr = null;

  }
  return xhr;
}

var xhr = createCORSRequest('GET', url);
if (!xhr) {
  throw new Error('CORS not supported');
}