好吧,我正在做一个网站,该网站应该从数据库中读取标记,然后将它们填充到地图上。如果我在本地工作,它可以正常工作,但是当我指向一个 php 文件在线时,因此不同的域(从 db 请求数据)我没有得到任何响应,并且我有 JSON.parse:意外的数据结束。请注意,我不想更改 php 文件中的任何内容,因为另一个网站已经在使用此文件。调用和执行请求的函数如下所示......非常感谢您的帮助。
function ajaxrequestDB() {
var AJAX = null; // Initialize the AJAX variable.
if (window.XMLHttpRequest) { // Does this browser have an XMLHttpRequest object?
AJAX=new XMLHttpRequest(); // Yes -- initialize it.
}
else { // No, try to initialize it IE style
AJAX=new ActiveXObject("Microsoft.XMLHTTP"); // Wheee, ActiveX, how do we format c: again?
} // End setup Ajax.
if (AJAX==null){ // If we couldn't initialize Ajax...
alert("Your browser doesn't support AJAX."); // Sorry msg.
return false // Return false, couldn't set up ajax
}
AJAX.onreadystatechange = function() { // When the browser has the request info..
if (AJAX.readyState==4 || AJAX.readyState=="complete")
{ // see if the complete flag is set.
//alert(AJAX.responseText);
var result =JSON.parse(AJAX.responseText);
//alert(AJAX.responseText);
for (var i=0; i<result.length; i++) {
for (var j=0; j<gmarkers.length; j++) {
if (gmarkers[j].myname == result[i].name) {
gmarkers[j].setVisible(true);
gcircle[j].bindTo('center', gmarkers[j], 'position');
gcircle[j].setVisible(true);
var cat = gmarkers[j].mycategory;
}
}
}
callback(AJAX.responseText, AJAX.status); // Pass the response to our processing function
} // End Ajax readystate check.
}
//var url='http://localhost/refresh.php'; //this works !
var url='http://anotherdomain.org/Scripts/refresh.php';
AJAX.open("GET", url, true); // Open the url this object was set-up with.
AJAX.send(); // Send the request.
}
function callback(x, y) {
// alert(x);
}