ajax и кодировка windows-1251

_S
На сайте с 11.01.2006
Offline
150
5652

		<script language="JavaScript" type="text/javascript">

//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest(); //Not IE
} else if(window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP"); //IE
} else {
//Display your error message here.
//and inform the user they might want to upgrade
//their browser.
alert("Your browser doesn't support the XmlHttpRequest object. Better upgrade to Firefox.");
}
}
//Get our browser specific XmlHttpRequest object.
var receiveReq = getXmlHttpRequestObject();
//Initiate the asyncronous request.
function sayHello(page) {
// alert(page);
//If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
//Setup the connection as a GET call to SayHello.html.
//True explicity sets the request to asyncronous (default).
receiveReq.open("GET", page, true);
//Set the function that will be called when the XmlHttpRequest objects state changes.
receiveReq.onreadystatechange = handleSayHello;
//Make the actual request.
receiveReq.send(null);
}
}
//Called every time our XmlHttpRequest objects state changes.
function handleSayHello() {
//Check to see if the XmlHttpRequests state is finished.
if (receiveReq.readyState == 4) {
//Set the contents of our span element to the result of the asyncronous call.
document.getElementById('span_result').innerHTML = receiveReq.responseText;
}
}
</script>

<a href="javascript:sayHello('1.html');">Say Hello</a><br />
<span id="span_result"></span>

Вот рабочий пример перезагрузки текста на странице с использованием AJAX.

Как заставить ajax понимать кодировку windows-1251 ?

Revolve - создание сайтов (http://www.revolving.ru/) icq 55-61-51
Kolyaj
На сайте с 28.03.2006
Offline
69
#1

Перед отправкой браузеру страницы явно указывайте кодировку в заголовках:


header("Content-type: text/html; charset=windows-1251");

P.S.: имеется в виду отправка контента объекту XMLHttpRequest

Ёжик В Тумане
На сайте с 26.07.2006
Offline
16
#2

используйте конструкцию:


<script type="texr/javascript" charset="windows-1251">

возможно поможет.

Ушел в себя, забыл про форум.
Вернусь ли? Не знаю... Если нужен, пишите в аську...
_S
На сайте с 11.01.2006
Offline
150
#3

Kolyaj, пасиб. Всё ок.

С меня пывос )))

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий