oBtn.onclick = function() {
var xhr = null;
try {
xhr = new XMLHttpRequest();
} catch (e) {
xhr = new ActiveXObject('Microsoft.XMLHTTP');
}
/*
1.缓存 在url?后面连接一个随机数,时间戳
2.乱码 编码encodeURI
*/
xhr.open('get','2.get.php',true);
xhr.send();
xhr.onreadystatechange = function() {
if ( xhr.readyState == 4 ) {
if ( xhr.status == 200 ) {
if(xhr.responseText == 'ok'){
alert('成功');
}else{
alert('失败');
}
} else {
alert('出错了,Err:' + xhr.status);
}
}
}
}
<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "Bill Gates\n\r";
fwrite($myfile, $txt);
$txt = "Steve Jobs\n\r";
fwrite($myfile, $txt);
if(fclose($myfile)){
echo 'ok';
}else{
echo 'no';
};
?>