利用javascript+webservice实现post方法
来源:互联网 发布:网络教学的设计原则 编辑:程序博客网 时间:2024/05/29 12:39
前台
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="LabPage1._Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>无标题页</title></head><script type="text/javascript" language="javascript"> var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); function callback1() { if(xmlhttp.status==200 && xmlhttp.readyState==4) { var textresponse=xmlhttp.responseText; var finddiv1=document.getElementById("div1"); finddiv1.innerText=textresponse; } } function RequestByPostOne(){ var data="name=NanceSun&gender=male"; var URL="http://202.119.43.9/WebService/Service1.asmx/MyPostLink"; xmlhttp.Open("POST",URL, false); xmlhttp.onreadystatechange=callback1; xmlhttp.SetRequestHeader ("Content-Type","application/x-www-form-urlencoded"); xmlhttp.Send(data); } function callback2() { if(xmlhttp.status==200 && xmlhttp.readyState==4) { var textresponse=xmlhttp.responseText; var finddiv1=document.getElementById("div2"); finddiv1.innerText=textresponse; } } function RequestByPostTwo(){ var data="i=30&j=31"; var URL="http://202.119.43.9/WebService/Service1.asmx/MyPostAdd"; xmlhttp.Open("POST",URL, false); xmlhttp.onreadystatechange=callback2; xmlhttp.SetRequestHeader ("Content-Type","application/x-www-form-urlencoded"); xmlhttp.Send(data); } </script><body><form runat="server"><br /><input type="button" value="Button1" onclick="RequestByPostOne()" /><div id="div1">DIVDIVDIVDIVDIVDIVDIVDIVDIV</div><br /><input type="button" value="Button2" onclick="RequestByPostTwo()" /><div id="div2">DIVDIVDIVDIVDIVDIVDIVDIVDIV</div><br /></form></body></html>
后台:
using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Linq;using System.Web;using System.Web.Services;using System.Web.Services.Protocols;using System.Xml.Linq;using System.IO;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;namespace WebService{ /// <summary> /// Service1 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.None)] [ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 // [System.Web.Script.Services.ScriptService] public class Service1 : System.Web.Services.WebService { [WebMethod(Description = "第一个函数,返回两个string的拼接", MessageName = "MyPostLink")] public string MyPostLink(string name, string gender) { return name + gender; } [WebMethod(Description = "第二个函数,返回两个int型的和", MessageName = "MyPostAdd")] public int MyPostAdd(int i, int j) { return i + j; } }}
- 利用javascript+webservice实现post方法
- 利用ScriptManager实现Javascript调用WebService中的方法
- 利用ScriptManager实现Javascript调用WebService中的方法
- 利用HttpWebRequest实现POST和GET方法
- JavaScript实现WebService的http的Post请求
- get/post方法调用 webservice
- linux下利用gsoap实现webservice通信方法详解
- 利用IWebBrowser2接口的Navigate2方法实现Http POST传输
- 利用IWebBrowser2接口的Navigate2方法实现Http POST传输
- 利用IWebBrowser2接口的Navigate2方法实现Http POST传输
- 利用HttpURLConnection实现get,post方法发送信息
- 利用javascript实现页面刷新的方法
- 利用javascript实现页面刷新的方法
- javascript利用arguments实现方法重载机制
- JavaScript实现调用WebService
- ajax javascript post 方法实现(与C#混合使用)
- 关于C#-POST方法和WebService方法
- 利用webservice实现无刷新
- Oracle常用监控SQL
- STM32 USB Mass Storage 例程调试笔记
- 腾讯实习生笔试题目(一)
- the main methos of class Ssh in pyssh module
- 进程共享数据封装成类
- 利用javascript+webservice实现post方法
- Android-SurfaceView与SurfaceHolder对象
- JS教程
- 20条编程经验
- apk反编译问题总结
- apk反编译问题总结
- Android Looper
- 123
- 比较一个对象list中的id值和List<Integer>的值是否相等