ajax post get
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的更多相关文章
- jQuery之ajax实现篇
jQuery的ajax方法非常好用,这么好的东西,你想拥有一个属于自己的ajax么?接下来,我们来自己做一个简单的ajax吧. 实现功能 由于jq中的ajax方法是用了内置的deferred模块,是P ...
- Ajax及跨域
概念 Ajax Ajax,Asynchronous JavaScript and XML,字面意思:异步的 JavaScript 和 XML,是指一种创建交互式网页应用的网页开发技术. 用于异步地去获 ...
- 一个粗心的Bug,JSON格式不规范导致AJAX错误
一.事件回放 今天工作时碰到了一个奇怪的问题,这个问题很早很早以前也碰到过,不过没想到过这么久了竟然又栽在这里. 当时正在联调一个项目,由于后端没有提供数据接口,于是我直接本地建立了一个 json ...
- ABP文档 - Javascript Api - AJAX
本节内容: AJAX操作相关问题 ABP的方式 AJAX 返回信息 处理错误 HTTP 状态码 WrapResult和DontWrapResult特性 Asp.net Mvc 控制器 Asp.net ...
- ajax异步请求
做前端开发的朋友对于ajax异步更新一定印象深刻,作为刚入坑的小白,今天就和大家一起聊聊关于ajax异步请求的那点事.既然是ajax就少不了jQuery的知识,推荐大家访问www.w3school.c ...
- 调用AJAX做登陆和注册
先建立一个页面来检测一下我们建立的用户名能不能用,看一下有没有已经存在的用户名吗 可以通过ajax提示一下 $("#uid").blur(function(){ //取用户名 va ...
- Ajax 概念 分析 举例
Ajax是结合了访问数据库,数据访问,Jquery 可以做页面局部刷新或者说是页面不刷新,我可以让页面不刷新,仅仅是数据的刷新,没有频繁的刷页面,是现在比较常用的一种方式做页面那么它是怎么实现页面无刷 ...
- ajax
常见的HTTP状态码状态码:200 请求成功.一般用于GET和POST方法 OK301 资源移动.所请求资源移动到新的URL,浏览器自动跳转到新的URL Moved Permanently304 未修 ...
- 学习笔记之MVC级联及Ajax操作
由于刚转型到MVC,MVC的架构模式很多不是很清楚,比如今天就想做个级联的操作,因为之前的ASP.NET的方式是通过:控件-->添加事件-->后台编写级联事件进行触发,但是这个MVC就不同 ...
- javascript表单的Ajax 提交插件的使用
Ajax 提交插件 form.js 表单的下载地址:官方网站:http://malsup.com/jquery/form/ form.js 插件有两个核心方法:ajaxForm()和ajaxSubmi ...
随机推荐
- 9.11 翻译系列:数据注解特性之--Timestamp【EF 6 Code-First系列】
原文链接:https://www.entityframeworktutorial.net/code-first/TimeStamp-dataannotations-attribute-in-code- ...
- HttpPost请求将json作为请求体传入的简单处理方法
https://www.cnblogs.com/mambahyw/p/7875142.html **************************************************** ...
- [译]Godot 引擎 GDNative 架构初探
GDNative的架构从最早叫"DLScript"的时候到目前为止已经发生了很大的变化.随着Godot 3.0版本接近最终发布以及API越来越稳定,是时候对GDNative目前的形 ...
- 【转】详解在visual studio中使用git版本系统(图文)
http://blog.csdn.net/wojilu/article/details/6976230 很多人已经在使用git(或正在转移到git上),在github.com上,也看到不少国内同学的开 ...
- Spring配置-数据库连接池proxool[转]
数据库连接是一种关键的有限的昂贵的资源,这一点在多用户的网页应用程序中体现得尤为突出.对数据库连接的管理能显著影响到整个应用程序的伸缩性和健壮性,影响到程序的性能指标.数据库连接池正是针对这个问题提出 ...
- plsql与64位的Oracle关联方法
在这里吐槽一下,plsql居然木有64位的,以前居然不知道,好久没用Oracle了,想练习一下,方法如下: 1.安装Oracle,官网都有,这里不细说了,我选的是64的Oracle安装的. 2.下载p ...
- Guava学习笔记(三):集合
添加Maven依赖 ListsTest import com.google.common.collect.Lists; import org.hamcrest.core.Is; import org. ...
- 针对phpStudy网站服务器的入侵
今天客户服务器上出现报警,查找了下原因,发现根目录下有wk.php E:\phpStudy\MySQL\bin\mysqld.exe, Version: (MySQL Community Server ...
- [GAN] Generative networks
中文版:https://zhuanlan.zhihu.com/p/27440393 原文版:https://www.oreilly.com/learning/generative-adversaria ...
- [React] 04 - Intro: mongoDB becomes popular
Ref: Linux平台安装MongoDB - 菜鸟教程 安装:sudo apt-get install mongodb 安装完毕产生: ls /etc/init.d/mongodb 配置:vim / ...