虚拟主机域名注册-常见问题网络编程问题 → JS


js原生ajax post和get数据
作者:

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");
			}
		};


来源:
阅读:935
日期:2021-05-29

推荐朋友 】 【 评论 】  【 字体: 】 
上一篇:js获取div内容
下一篇:div可编辑 enter或离开焦点后提交数据
  >> 相关文章
  没有相关文章。
发表评论


点  评: 字数0
用户名:  密码:

  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款