js原生ajax post和get数据

2024-02-15 17:46:35 举报文章

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");
			}
		};
如果你认为本文可读性较差,内容错误,或者文章排版错乱,请点击举报文章按钮,我们会立即处理!