Ajax网络请求基本用法
来源:互联网 发布:编程语言应用领域 编辑:程序博客网 时间:2024/05/16 06:57
<!DOCTYPE html><html lang="Zh-cn"><head> <meta charset="UTF-8"> <title>网络请求Dome</title></head><body><h1>员工查询</h1><label>请输入员工编号:</label><input type="text" id="keywords"><button id="search">查询</button><p id="searchResult"></p><h1>员工新建</h1><label>请输入员工姓名:</label><input type="text" id="name"><br><label>请输入员工编号:</label><input type="text" id="number"><br><label>请输入员工性别:</label><select id="sex"> <option value="man">男</option> <option value="woman">女</option></select><br><label>请输入员工职位:</label><input type="text" id="position"><br><button id="save">保存</button><br><p id="saveResult"></p><script scr="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.js"></script><script>//jQuery中 Ajax普通请求$(document).ready(function() { $("#search").click(function() { $.ajax({ url: 'url', type: 'default GET (Other values: POST)', dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)', data: {param1: 'value1'}, }) .done(function() { console.log("success"); }) .fail(function() { console.log("error"); }) .always(function() { console.log("complete"); }); j });});//javascript中 Ajax普通请求document.getElementById("search").onclick= function() { //新建一个请求 var request = new XMLHttpRequest(); //设置请求请求方式,参数, request.option("GET","url?number="+document.getElementById("keywords").value); //发送请求 request.send(); //获取响应结果 request.onreadystatechange = function() { if (request.readyState ===4) { if (request.status ===200) { var data = JSON.parse(request.responseText); if (data.success) { //请求成功,刷新页面 document.getElementById("saveResult").innerHTML=data.msg; } else { document.getElementById("saveResult").innerHTML="发生错误:"+data.msg; } } else { alert("发生错误:"+request.status); } } }}document.getElementById("save").onclick= function() { //新建一个Ajax请求 var request = new XMLHttpRequest(); //设置请求请求方式,参数, request.option("POST","url"); //构造请求参数 var data = "name="+document.getElementById("name").value +"number="+document.getElementById("number").value +"sex="+document.getElementById("sex").value +"position="+document.getElementById("position").value; request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); //发送请求 request.send(data); //获取响应结果 request.onreadystatechange = function() { if (request.readyState ===4) { if (request.status ===200) { var data = JSON.parse(request.responseText); if (data.success) { //请求成功,刷新页面 document.getElementById("searchResult").innerHTML=data.msg; } else { document.getElementById("searchResult").innerHTML="发生错误:"+data.msg; } } else { alert("发生错误:"+request.status); } } }}</script></body></html>
0 0
- Ajax网络请求基本用法
- 03网络请求_02_Volley_1_基本用法
- JQuery 实现AJAX异步请求 的基本用法
- ajax请求基本方式
- Android Retrofit+rxjava+okhttp请求网络的基本用法
- ajax异步网络请求
- Fetch基本网络请求
- ajax 基本用法
- Ajax最基本用法
- Ajax的基本用法
- Ajax的基本用法
- JQ AJax基本用法
- ajax基本用法
- Ajax基本用法
- Ajax基本用法
- ajax基本用法
- ajax的基本用法
- Ajax发送网络请求包装
- java组合排序
- springboot如何接入dubbo
- FL2440添加DS18B20驱动
- Lucene4.4.0几种分词方法
- Java进阶(五)Junit测试
- Ajax网络请求基本用法
- 当在一个方法中需要返回多个参数时的做法
- 遍历显示时一行白色一行灰色效果
- JQuery中$.ajax()方法参数详解
- notepad++设置tab为4个空格
- 【多媒体封装格式详解】---MKV【2】
- hihocode _1051 补提交卡
- 自定义C++ trim函数出现的小问题
- http TCP/IP 相关笔记