1.Ajax   post 方法

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AJAXtest.aspx.cs" Inherits="treeview.AJAXtest" %>

<!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 id="Head1" runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Ajax实例1</title>
<script src="js/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
$(function () {
$("#btn1").click(function () {
var txtparam1 = $("#txtParam1").val();
var txtparam2 = $("#txtParam2").val(); $.ajax({
url: "RepeatName.ashx",//发送到本页面后台AjaxMethod方法 "AJAXtest.aspx/AjaxMethod"
type: "POST",
dataType: "json",//返回格式必须是json格式,否则会进error方法,如果去掉可以接受任意的格式数据。
            //后台如果传自定义类 的数据 该如何接收? 后台需要用newtonsoft把类转换成json数据 返回。然后前端在success里直接 data.id即可。
async: true,//async翻译为异步的,false表示同步,会等待执行完成,true为异步
contentType: "application/json; charset=utf-8",//不可少
data: "{param1:'" + txtparam1 + "',param2:'" + txtparam2 + "'}",
success: function (data) {
$("#result").html(data.d);
},
error: function () {
alert("请求出错处理");
}
}); });
});
</script>
</head>
<body>
<form id="form1" runat="server">
参数1:<input type="text" id="txtParam1" value="" /><br />
参数2:<input type="text" id="txtParam2" value="" /><br />
<input type="button" id="btn1" value="提交"/><br />
<div id="result"></div>
</form>
</body>
</html>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq; namespace treeview
{
public partial class AJAXtest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int dfe = ;
} //type方式必须是post,方法必须是静态的,方法声明要加上特性[System.Web.Services.WebMethod()],传递的参数个数也应该和方法的参数相同。
[System.Web.Services.WebMethod()]
public static string AjaxMethod(string param1, string param2)
{
return "1参数为:" + param1 + ",2参数为:" + param2;
} }
}

2. Ajax  get

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ajaxGet.aspx.cs" Inherits="treeview.ajaxGet" %>

<!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 id="Head1" runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Ajax实例1</title>
<script src="js/jquery-1.4.4.min.js"></script>
<script language="Javascript">
function RepeatName() {
var name = $("#txtLoginName").val();
$.ajax({
type: "GET",
url: "RepeatName.ashx",
data: "name=" + name, //如果这里是传多个参数的话 可以写成 date: "name="+name+"&"+"其它的名字="+页面获取的val();
cache: false,
async: false,
success: function (data) { if (data == "") {
alert("此用户已经注册");
}
else{
alert("没有注册");
}
},
error: function () {
alert("请求出错处理");
}
});
}
</script>
</head>
<body>
<div>
<input type="text" name="txtLoginName" id="txtLoginName" onblur="return RepeatName()" />
<span style="color: red; font-size: 13px" id="txtLoginNamespan"> </span>
</div>
</body>
</html>
using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq; namespace treeview
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class RepeatName : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World"); string name = context.Request.QueryString["param1"];
if (name == "")
{
context.Response.Write("");
}
else
{
context.Response.Write("Hello World");
}
} public bool IsReusable
{
get
{
return false;
}
}
}
}

ajax post get的更多相关文章

  1. jQuery之ajax实现篇

    jQuery的ajax方法非常好用,这么好的东西,你想拥有一个属于自己的ajax么?接下来,我们来自己做一个简单的ajax吧. 实现功能 由于jq中的ajax方法是用了内置的deferred模块,是P ...

  2. Ajax及跨域

    概念 Ajax Ajax,Asynchronous JavaScript and XML,字面意思:异步的 JavaScript 和 XML,是指一种创建交互式网页应用的网页开发技术. 用于异步地去获 ...

  3. 一个粗心的Bug,JSON格式不规范导致AJAX错误

    一.事件回放  今天工作时碰到了一个奇怪的问题,这个问题很早很早以前也碰到过,不过没想到过这么久了竟然又栽在这里. 当时正在联调一个项目,由于后端没有提供数据接口,于是我直接本地建立了一个 json ...

  4. ABP文档 - Javascript Api - AJAX

    本节内容: AJAX操作相关问题 ABP的方式 AJAX 返回信息 处理错误 HTTP 状态码 WrapResult和DontWrapResult特性 Asp.net Mvc 控制器 Asp.net ...

  5. ajax异步请求

    做前端开发的朋友对于ajax异步更新一定印象深刻,作为刚入坑的小白,今天就和大家一起聊聊关于ajax异步请求的那点事.既然是ajax就少不了jQuery的知识,推荐大家访问www.w3school.c ...

  6. 调用AJAX做登陆和注册

    先建立一个页面来检测一下我们建立的用户名能不能用,看一下有没有已经存在的用户名吗 可以通过ajax提示一下 $("#uid").blur(function(){ //取用户名 va ...

  7. Ajax 概念 分析 举例

    Ajax是结合了访问数据库,数据访问,Jquery 可以做页面局部刷新或者说是页面不刷新,我可以让页面不刷新,仅仅是数据的刷新,没有频繁的刷页面,是现在比较常用的一种方式做页面那么它是怎么实现页面无刷 ...

  8. ajax

    常见的HTTP状态码状态码:200 请求成功.一般用于GET和POST方法 OK301 资源移动.所请求资源移动到新的URL,浏览器自动跳转到新的URL Moved Permanently304 未修 ...

  9. 学习笔记之MVC级联及Ajax操作

    由于刚转型到MVC,MVC的架构模式很多不是很清楚,比如今天就想做个级联的操作,因为之前的ASP.NET的方式是通过:控件-->添加事件-->后台编写级联事件进行触发,但是这个MVC就不同 ...

  10. javascript表单的Ajax 提交插件的使用

    Ajax 提交插件 form.js 表单的下载地址:官方网站:http://malsup.com/jquery/form/ form.js 插件有两个核心方法:ajaxForm()和ajaxSubmi ...

随机推荐

  1. System.SerializableAttribute

    System.SerializableAttribute 串行化是指存储和获取磁盘文件.内存或其他地方中的对象.在串行化时,所有的实例数据都保存到存储介质上,在取消串行化时,对象会被还原,且不能与其原 ...

  2. linux每日命令(17):which命令

    我们经常在linux要查找某个文件,但不知道放在哪里了,可以使用下面的一些命令来搜索: which 查看可执行文件的位置. whereis 查看文件的位置. locate 配合数据库查看文件位置. f ...

  3. JavaScript Scroll家族以及封装

    JavaScript Scroll家族以及封装 scrollTop & scrollLeft 别卷去的值,就是当滑动滚轮浏览网页的时候,网页隐藏在屏幕上方或左侧的距离 获得scrollTop ...

  4. Java知多少(55)线程

    和其他多数计算机语言不同,Java内置支持多线程编程(multithreaded programming). 多线程程序包含两条或两条以上并发运行的部分.程序中每个这样的部分都叫一个线程(thread ...

  5. 随笔:JS对象无new构造原理

    var myFun = function(words) { if (!(this instanceof myFun)) { return new myFun(words); } this.name = ...

  6. spark 解析非结构化数据存储至hive的scala代码

    //提交代码包 // /usr/local/spark/bin$ spark-submit --class "getkv" /data/chun/sparktes.jar impo ...

  7. 修改git用户密码

    第一步:登录git服务器: 第二步:切换到git用户 su git 第三步:登录GitLab的Rails控制台(GitLab使用RoR语言开发), gitlab-rails console produ ...

  8. Git错误:error: The following untracked working tree files would be overwritten by merge:

    [andy@localhost weixin_robot]$ git pull Updating d652d1c..fa05549 error: The following untracked wor ...

  9. yum 快速安装centos7 mysql5.7

    CentOS7 yum方式安装MySQL5.7   在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要,还是要在系统中安装MySQL,而且安装完成之后可以直接覆盖掉Maria ...

  10. Java 简单的rpc 一

    一,简单rpc 是基于Java socket 编程 ServerSocket serverSocket = new ServerSocket(9999); System.out.println(&qu ...