ajax 调用asp.net后台方法
ajax 调用asp.net后台方法
这种做法有好几种,如调用xx.asxh 页面,或者直接调用xx.aspx也面,在page_Load中进行一些判断然后调用后面的其他方法,
或者你可以直接调用webservice;
今天我简单总结一中方法,前提是:net Framework 4.0以上的版本才支持滴呀(包括4.0),也就是说:2.0 和 3.0 都不支持滴呀
前端写法:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication3.WebForm1" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" value="ClientClick有参数" onclick="TestAjaxParam()"/>
<input type="button" value="ClientClick2不带参数" onclick="TestAjax()"/>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
<script type="text/javascript" src="jq/jquery-1.9.1.js"></script>
<script type="text/javascript"> //客户端控件
//带参数的
function TestAjaxParam(){
$.ajax({
type:"POST",
url: "WebForm1.aspx/TestAjaxParam",
data:'{Name:"jack"}',
dataType:"text",
contentType:"application/json; charset=utf-8",
success:function (data){
alert(data);
}
})
} //不带参数的
function TestAjax(){
$.ajax({
type:"POST",
url: "WebForm1.aspx/TestAjax",
dataType:"text",
contentType:"application/json; charset=utf-8",
success:function (data){
alert(data);
}
})
} //服务端控件
//"Default.aspx/Test",
//"Default.aspx/TestAjax",
$("#Button1").bind("click",function (){
$.ajax({
type:"post",
url: "WebForm1.aspx/TestAjax",
contentType:"application/json; charset=utf-8",
dataType:"text",
success:function (data){
alert(data);
}
});
//禁止按钮的提交
return false;
}) </script>
</body>
</html>
后端方法
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; namespace WebApplication3
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } public static string showString()
{
System.Threading.Thread.Sleep();
return "this method come from codeBind";
} public static string Test()
{
return "Test";
}
//有参数
[System.Web.Services.WebMethod]
public static string TestAjaxParam(string Name)
{
System.Threading.Thread.Sleep();
return "this method come from codeBind" + Name; }
//无参数
[System.Web.Services.WebMethod]
public static string TestAjax()
{
System.Threading.Thread.Sleep();
return "this method come from behide"; } }
}
ajax 调用asp.net后台方法的更多相关文章
- JQuery Ajax调用asp.net后台方法
利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法. 先来个简单的实例热热身吧. 1.无参数的方法调用 asp.net code: using System.Web.Scrip ...
- jQuery.ajax()调用asp.net后台方法
利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法.介意方法名不要重名 建一个WebFormAjax名aspx文件 CS <%@ Page Language=" ...
- jQuery.ajax()调用asp.net后台方法(非常重要)
http://www.cnblogs.com/zxhoo/archive/2011/01/30/1947752.html 用JQuery的$.ajax()可以很方便的调用asp.net的后台方法. 先 ...
- .Net中jQuery.ajax()调用asp.net后台方法 总结
利用JQuery的$.ajax()调用.Net后台方法有多种方式, 不多说了 直接上代码 前台代码 <script type="text/javascript"> $ ...
- jQuery调用Asp.Net后台方法
常用的ajax就不讲了,这里主要是说通过ajax调用asp.net后台的cs文件暴露的方法. 前台: <%@ Page Language="C#" AutoEventWire ...
- 利用JQuery直接调用asp.net后台方法
利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法. [WebMethod] 命名空间 1.无参数的方法调用, 注意:1.方法一定要静态方法,而且要有[WebMethod] ...
- JS调用asp.net后台方法:PageMethods
先帮朋友宣传一下程序人生(http://www.manong123.com)的网站,里面都是开发感悟,开发人员创业,支持一下吧~ 原来是通过PageMethods来实现的. 举个列子: Default ...
- Ajax调用asp.net后台代码
后台代码: [WebMethod] public static string CreateDate(string name,string age) { return "姓名:"+n ...
- JQuery ajax调用asp.net的webMethod
本文章转载:http://www.cnblogs.com/zengxiangzhan/archive/2011/01/16/1936938.html 在vs2010中,用JQuery ajax调用as ...
随机推荐
- Metronic_下拉列表Select2插件的使用
这个插件是基于Select的扩展插件,能够提供更加丰富的功能和用户体验,它的github官网地址为:https://select2.github.io/,具体的使用案例,可以参考地址:https:// ...
- FlyCaptureProperty 摄像机属性
An enumeration of the different camera properties that can be set via the API. Declaration enum FlyC ...
- hdu 最大报销额
本题也是一个背包的问题,我觉得这道题的核心就是根据精确度将浮点型转化为整型然后利用动态规划进行求解,注意对题意的理解,有3种支票是不能够报销的. 我开始照着这个思路进行思考,但是敲出来的第一个代码居然 ...
- sqlmap我常用到的几个参数
-r "抓的包存放的文件路径.txt" 一般方便带cookie与session类型 --dbms Oracle/Mysql 指定数据库类型 指定变量注入点变量:在变量 ...
- JavaWEB入门
首先,我们已知的是Web资源分为:静态web资源(如html 页面):指web页面中供人们浏览的数据始终是不变.常用的静态web开发技术即为html:动态web 资源:指web页面中供人们浏览的数据是 ...
- storm在linux系统下安装调试
安装: 安装 zookeeper : 下载 zookeeper :http://zookeeper.apache.org/releases.html#download. 将 zookeeper-3.4 ...
- Using Vertex Texture Displacement for Realistic Water Rendering
http://blog.csdn.net/soilwork/article/details/709869 Using Vertex Texture Displacement for Realistic ...
- centos 使用pip安装mysql-python
直接使用# pip install mysql-python 命令报 EnvironmentError: mysql_config not found 错误 安装mysql-phthon 需要用的my ...
- Yii源码阅读笔记(十八)
View中的查找视图文件方法和渲染文件方法 /** * Finds the view file based on the given view name. * 通过view文件名查找view文件 * ...
- BundleConfig 的使用 通配符
//是不是说一定要是前缀文件呢 OK 通过 通配符只能使用在前缀或后缀 //捆绑名称 bundles.Add(new StyleBundle("~/caijinhao/caijinhao&q ...