masious
جمعه 22 شهریور 1392, 05:56 صبح
سلام.
من برای ای جکس هام، آبجکت زیر رو ساختم، ولی نمی دونم چرا دیتایی که می خوام با متد ای جکس بفرستم، نمیره:
ajax = {
method: 'POST',
finish: function(){},
error: function(){},
open: function(){},
init: function( url ){
try{
this.con = new XMLHttpRequest();
}
catch( e ){
alert( "Sorry. Your browser is not supported." );
return false;
}
this.con.open( this.method , url , true );
this.con.setRequestHeader( "Content-Type" , ( this.method == 'POST' ) ? "application/" : '' + "x-www-form-urlencoded; charset=UTF-8" );
},
send: function( data ){
var rData = '';
if( data != null ){
if( typeof data != 'object'){
return false;
}
if( data.length == undefined ){
for( var i in data ){
rData += i + "=" + data[ i ] + "&";
}
}
else{
for( var i = 0 ; i < data.length ; i++ ){
rData += "data" + i + "=" + data[ i ] + "&";
}
}
rData = rData.replace(/&$/,"");
this.data = rData;
if( this.method == 'POST' ){
this.con.setRequestHeader( "Content-length" , this.data.length );
this.con.setRequestHeader( "Connection" , "close" );
}
}
this.con.send( rData );
this.con.addEventListener( 'readystatechange' , function(){
ajax.rs = this.readyState;
switch (this.readyState){
case 1:
ajax.open();
break;
case 4:
if( this.status == 200 || this.status == 304 )
ajax.finish( this.responseText );
break;
}
} , false);
}
};
برای استفاده هم:
ajax.init( 'set.php?token=' + token );
ajax.send( { "msg": content, "receiver": receiver } );
ajax.finish = function( msg ){
alert( msg );
}
من برای ای جکس هام، آبجکت زیر رو ساختم، ولی نمی دونم چرا دیتایی که می خوام با متد ای جکس بفرستم، نمیره:
ajax = {
method: 'POST',
finish: function(){},
error: function(){},
open: function(){},
init: function( url ){
try{
this.con = new XMLHttpRequest();
}
catch( e ){
alert( "Sorry. Your browser is not supported." );
return false;
}
this.con.open( this.method , url , true );
this.con.setRequestHeader( "Content-Type" , ( this.method == 'POST' ) ? "application/" : '' + "x-www-form-urlencoded; charset=UTF-8" );
},
send: function( data ){
var rData = '';
if( data != null ){
if( typeof data != 'object'){
return false;
}
if( data.length == undefined ){
for( var i in data ){
rData += i + "=" + data[ i ] + "&";
}
}
else{
for( var i = 0 ; i < data.length ; i++ ){
rData += "data" + i + "=" + data[ i ] + "&";
}
}
rData = rData.replace(/&$/,"");
this.data = rData;
if( this.method == 'POST' ){
this.con.setRequestHeader( "Content-length" , this.data.length );
this.con.setRequestHeader( "Connection" , "close" );
}
}
this.con.send( rData );
this.con.addEventListener( 'readystatechange' , function(){
ajax.rs = this.readyState;
switch (this.readyState){
case 1:
ajax.open();
break;
case 4:
if( this.status == 200 || this.status == 304 )
ajax.finish( this.responseText );
break;
}
} , false);
}
};
برای استفاده هم:
ajax.init( 'set.php?token=' + token );
ajax.send( { "msg": content, "receiver": receiver } );
ajax.finish = function( msg ){
alert( msg );
}