私が作った未加工のXMLHttpRequestポスト関数と、その他いくつかの機能があります。下位互換性があります。
function phpEncode(obj){
var r = [];
if(obj instanceof Array){
for(var i=0,l=obj.length; i<l; i++){
r.push(phpEncode(obj[i]));
}
return '%5B'+r.join(',')+'%5D';
}
else if(typeof obj === 'object' && obj){
for(var i in obj){
if(obj.hasOwnProperty(i)){
var v = obj[i], s;
if(typeof v === 'object' && v){
s = encodeURIComponent('"'+i.replace('"', '\\"')+'":')+phpEncode(v);
}
else{
v = typeof v === 'string' ? '"'+v.replace('"', '\"')+'"' : v;
s = encodeURIComponent('"'+i.replace('"', '\\"')+'":'+v);
}
r.push(s);
}
}
return '%7B'+r.join(',')+'%7D';
}
else{
r = typeof obj === 'string' ? '"'+obj.replace('"', '\\"')+'"' : obj;
return ''+r;
}
}
function phpAccept(respText){
return eval('('+decodeURIComponent(respText)+')');
}
function clone(obj){
return phpAccept(phpEncode(obj));
}
function post(send, where, success, context){
var x = new XMLHttpRequest || new ActiveXObject('Microsoft.XMLHTTP');
var c = context || this;
x.open('POST', where); x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
x.onreadystatechange = function(){
if(x.readyState === 4 && x.status === 200){
if(success)success.call(c, phpAccept(x.responseText));
}
}
if(send && typeof send === 'object' && !(send instanceof Array)){
var r = [];
for(var p in send){
r.push(encodeURIComponent(p)+'='+phpEncode(send[p]));
}
if(r.length)x.send(r.join('&'));
}
return x;
}
post({testProperty:'testValue'}, 'yourPage.php', function(response){
// evaluate response and run all your other code here
});
「動作しない」とはどういう意味ですか?正確に何がうまくいかないのですか?この場合、ajaxとは何ですか?あなたがするべきであるように、あなたはajaxコールのコールバックでこれをしていないと推測しています。また、 "テキスト" が引用符 – Pabs123
'ajax.onreadystatechange =関数(){ \t IF(ajaxReturn(AJAX)== TRUE){ IF(ajax.responseText){ idisis = ajax.responseTextを有するべきです。 document.getElementById(idisis).innerHTML = "some text"; } \t} } '何も起こらない –