Как таковая функция не поддерживает междоменный запрос
function makeRequest(url) {
var http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create an XMLHTTP instance');
return false;
}
http_request.onreadystatechange = function() { alertContents(http_request); };
http_request.open('GET', url, true);
http_request.send(null);
}
function alertContents(http_request) {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
receiveData(http_request.responseText);
} else {
alert("error");
}
}
}
поэтому решил использовать jQuery (с этим плагином ), но с функцией
$.ajax({
url: suchurl,
type: "GET",
//dataType: "text",
dataType: "text",
//global: false,
//async:false,
cache: false,
success: function(data) {
//alert(data);
alert(data.responseText);
}
});
вывод как
<html>
<head>
<meta content="HTML Tidy for Java (vers. 26 Sep 2004), see www.w3.org" name="generator"/>
<title/>
</head>
<body>
<p>new_towns = [ {id:"0", name:" "},
{id:"205",
name:"City205"},
{id:"17",
name:"City17"}
];</p>
</body>
</html>
Почему? .. ожидая только
new_towns = [ {id:"0", name:" "}, {id:"205", name:"City205"}, {id:"17", name:"City17"} ];
Что вы посоветуете?
Заранее благодарю.
такой пример кода - не работает
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.6.2");
google.setOnLoadCallback(function() {
$.ajax({
url: suchurl,
type: "GET",
dataType: "text",
crossDomain:true,
async:true,
cache: false,
success: function(data) {
alert("all right");
}
});
});
</script>
</head>
<body>
</body>
</html>
ОК, ребята, это более простой и быстрый и понятный скрипт использования решений
get.php
<?php
if(isset($_POST['geturl']) and !empty($_POST['geturl'])) {
$data = file_get_contents($_POST['geturl']);
print $data;
}
?>
, а затем просто
$.ajax({ url: 'get.php',
data: {geturl: suchurl},
type: 'POST',
dataType: "text",
cache: false,
success: function(data){
alert(data);
//do something else
}
});
TNX ОЧЕНЬ ОЧЕНЬ ВАШИ ПОПЫТКИ ПОМОЧЬ И СОВЕТЫ!