zoukankan      html  css  js  c++  java
  • ajax_demo:GET POST发送数据

    GET,通过url发送数据

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script language="JavaScript">
    var xmlHttp; function login() { if(window.XMLHttpRequest){ xmlHttp=new XMLHttpRequest(); }else{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } var name = document.getElementById("name").value; var password = document.getElementById("password").value; var url = "/Crawler/Login?name="+name+"&password="+password; xmlHttp.open("GET", url, true); xmlHttp.send(null); } </script> </head> <body> 用户名:<input type="text" name="name" id="name"/></br> 密码:<input type="password" name="password" id="password"/></br> <button type="button" onclick="login();">登陆</button> </body> </html>

    POST:通过XMLHttpRequest.send(),发送xml格式数据,需在header中设置Content-Type:text/xml

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script language="JavaScript">
    var xmlHttp;
    function login() { if(window.XMLHttpRequest){ xmlHttp=new XMLHttpRequest(); }else{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } alert("send ok") var name = document.getElementById("name").value; var password = document.getElementById("password").value; var xmlString = "<profile>" + " <name>" + escape(name) + "</name>" + " <password>" + escape(password) + "</password>" + "</profile>"; var url = "/Crawler/Login"; xmlHttp.open("POST", url, true); xmlHttp.setRequestHeader("Content-Type", "text/xml"); xmlHttp.send(xmlString);//发送数据 } </script> </head> <body> 用户名:<input type="text" name="name" id="name"/></br> 密码:<input type="password" name="password" id="password"/></br> <button type="button" onclick="login();">登陆</button> </body> </html>
  • 相关阅读:
    ABP Xunit单元测试 第五篇
    ABP 异常处理 第四篇
    ABP Quartz 作业调度第三篇
    ABP 权限拦截 第二篇
    ABP .NET corej 版本 第一篇
    Vue生命周期
    vue中的import、export、requre的区别
    ES6最新语法
    Vux项目搭建
    对象克隆
  • 原文地址:https://www.cnblogs.com/yunwuzhan/p/5846692.html
Copyright © 2011-2022 走看看