分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

js ajax请求

发布时间:2023-09-06 01:16责任编辑:彭小芳关键词:js

Ajax API

var reqUrl = "http://192.168.31.162:8081/obtain/onlineState?name=aa01&password=010203";var postUrl = "http://192.168.31.162:8081/update/remoteClientInfo";/** * 页面 * ???http://192.168.31.162:8081/http/ajax/Aj01-HttpRequest.html * ajax get 请求 * ?http://www.w3school.com.cn/ajax/ajax_xmlhttprequest_send.asp */function testAjaxGet() { ???debugger; ???var xmlhttp; ???if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari ???????xmlhttp = new XMLHttpRequest(); ???} ???else {// code for IE6, IE5 ???????xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); ???} ???xmlhttp.open("GET", reqUrl, true);// ???????xmlhttp.open("GET", reqUrl, false); ???xmlhttp.send();// ???????console.log(xmlhttp.responseText); ???xmlhttp.onreadystatechange = function () { ?// 异步方法回调 ???????if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { ???????????console.log(xmlhttp.responseText); ???????} ???}}/** * Ref: * */function testAjaxPost() { ???debugger; ???var xmlhttp; ???if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari ???????xmlhttp = new XMLHttpRequest(); ???} ???else {// code for IE6, IE5 ???????xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); ???} ???xmlhttp.open("POST", postUrl, true);// ???????xmlhttp.open("POST", postUrl, false); ???xmlhttp.setRequestHeader("Content-type","application/json"); ???var jsonObj = { ???????name:"AAA" ???}; ???xmlhttp.send(JSON.stringify(jsonObj));// ???????console.log(xmlhttp.responseText); ???xmlhttp.onreadystatechange = function () { ?// 异步方法回调 ???????if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { ???????????console.log(xmlhttp.responseText); ???????} ???}}

参考:

     AJAX - 向服务器发送请求 w3c

js ajax请求

原文地址:http://www.cnblogs.com/zhen-android/p/7643382.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved