post方法
function sendsms(){ var xhr = new XMLHttpRequest(); xhr.open('POST', 'http://www.sinmeng.net/send.php' ); xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xhr.send('action=send&mobphone=$mobphone&content=$content&type=2'); xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) { if(xhr.responseText=='ok'){ layer.msg('验证码送成功', {icon: 1}); }else{ alert(xhr.responseText); } } }; }
GET方法
var xhr = new XMLHttpRequest(); xhr.open('GET', 'http://www.sinmeng.net/sendsms/send.php?action=check&mobphone=$mobphone&num=$num'); xhr.send(); xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) { alert("success"); } };