Ajax code dose not working properly

ldoroni

Sorry for my english...

why this ajax code dosen't work properly ?

when I call the POST variable in the page that i send for him the info, its show me that the POST variable is not exist...

Can anybody explain why it is happening ?

part of the ajax code:

var xhr = new XMLHttpRequest();
xhr.open("POST",url,true);
xhr.onreadystatechange = function() {
    if( this.readyState == 4 && this.status == 200) {
        document.getElementById(name).innerHTML = this.responseText;
    }
};
xhr.send("info="+str+"&info_1="+info_1+"&info_2="+info_2);
return false;
Pyrech

Some headers must be included for POST request:

xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Content-length", params.length);
xhr.setRequestHeader("Connection", "close");

Edit :

My script use a variable called 'params'. So add a var at the beginning of your script and put in it the content of your request :

var params = "info="+str+"&info_1="+info_1+"&info_2="+info_2;

And replace in the call of xhr.send "info="+str+"&info_1="+info_1+"&info_2="+info_2; by params:

xhr.send(params);

Here is the final script:

var xhr = new XMLHttpRequest();
var params = "info="+str+"&info_1="+info_1+"&info_2="+info_2;
xhr.open("POST",url,true);
xhr.onreadystatechange = function() {
    if( this.readyState == 4 && this.status == 200) {
        document.getElementById(name).innerHTML = this.responseText;
    }
};
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Content-length", params.length);
xhr.setRequestHeader("Connection", "close");
xhr.send(params);
return false;

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

MVC Ajax alert not working properly

분류에서Dev

retrieving images from server using ajax, jQuery. code not working

분류에서Dev

Fn key not properly working

분류에서Dev

debounce (AfterValueChanged) Not working properly

분류에서Dev

Array Enumeration Not Working Properly?

분류에서Dev

listview setItemChecked not working properly

분류에서Dev

Rspec is not working properly with mongodb

분류에서Dev

Simple slideshow not working properly

분류에서Dev

Navigation Properties are not working properly

분류에서Dev

Fitviewport not working properly

분류에서Dev

For loop is not working properly in nodejs

분류에서Dev

Back Key not working properly

분류에서Dev

ps command not working properly?

분류에서Dev

Matlab loop not working properly

분류에서Dev

Sed into Variable not working properly

분류에서Dev

gnome-bluetooth not working properly

분류에서Dev

Wine games resolution not working properly

분류에서Dev

Left side of screen not working properly

분류에서Dev

Codeigniter not working properly when hosted

분류에서Dev

bootstrap 3 tabs not working properly

분류에서Dev

Querying datatable with Linq not working properly

분류에서Dev

Accordian selected dt not working properly

분류에서Dev

Regex Curly brackets not working properly

분류에서Dev

$.when with arrays of functions is not working properly

분류에서Dev

Bootstrap sidebar and footer not working properly

분류에서Dev

Make Startup Disk not working properly

분류에서Dev

FPDF not working properly in some browsers

분류에서Dev

Command not working properly in shell script

분류에서Dev

Login with jQuery AJAX is not working