AJAX ScriptManagerProxy调用webservice
内容页:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ScriptManagerProxyDemo.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<script type="text/javascript">
function EchoUserInput() {
var echoElem = $get("EnteredValue");
alert(echoElem);
ScriptManagerProxyDemo.WebService1.EchoInput(echoElem.value, OnSucceeded);
}
function OnSucceeded(result)
{
var RsltElem = $get("Results");
RsltElem.innerHTML=result;
}
</script>
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
<Services>
<asp:ServiceReference Path="~/WebService1.asmx" />
</Services>
</asp:ScriptManagerProxy>
<input type="text" id="EnteredValue" /><input type="button" onclick="EchoUserInput()"/>
<div id="Results"></div>
</asp:Content>
webservice:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace ScriptManagerProxyDemo
{
/// <summary>
/// WebService1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile
相关文档:
这是最常用的地址选择下拉框,包括三个下拉框,对应三个XML文件:
--------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<Provinces>
<Province ID="1" ProvinceName="北京市">北京市</Province>
<Province ID= ......
1. 适当使用UpdatePanel
2. 利用WebService方法动态生成用户控件的内容,避免UpdatePanel回传造成的性能损失(ViewState)
3. ToolkitScriptManager代替ScriptManager
4. <asp:ScriptManager runat="server" ID="sm" ScriptMode="Release" EnablePartialRendering="false"
......
我们可以使用XML作为数据传送、沟通的格式,Ajax客户端若要发送XML,基本上就是将XML作为字符串,在POST请求时发送,例如:
*HelloAjax.js
view plaincopy to clipboardprint?
var xmlHttp;
function createXMLHttpRequest() {
if (window.XMLHttpRequest) {   ......
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp=new ActiveXObject("Microsoft.XMLhTTP");
}
else if(window.XMLHttpRequest){
xmlHttp=new ......
标准XMLHttpRequest操作
abort()
停止当前请求
getAllResponseHeaders()
把HTTP请求的所有响应首部作为键/值对返回
getResponseHeader("header")
返回指定首部的串值
void open(string method, string url, boolean asynch)
建立对服务器的调用。method参 ......