Mobile App VS .NET Communication Through Ajax
2015-06-19 16:50
260 查看
Client Side(Web App)
<script src="js/mui.min.js"></script>
<button onclick="GetWithCallback()">测试jquery.get</v></button><br/>
<button onclick="PostWithCallback()">测试jquery.post</v></button><br/>
<script>
//测试get,使用回调函数
//注意:get()方法提供了回调函数(callback),该函数有三个参数,分别代表请求返回的内容、请求状态和XMLHttpRequest对象
function GetWithCallback() {
$.get("http://222.178.71.253:8033/Default.aspx", { "param": "TestGet-Callback" }, function (responseText, textStatus, XMLHttpRequest) {
$("#result").html("回调函数在起作用,结果:" + responseText);
});
}
//测试post,使用回调函数
function PostWithCallback() {
$.post("http://222.178.71.253:8033/Default.aspx", { "param": "TestPost-Callback" }, function (responseText, textStatus, XMLHttpRequest) {
$("#result").html("回调函数在起作用,结果:" + responseText);
});
}
</script>
.NET side
client
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="GetMethodInfo._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Welcome to ASP.NET!
</h2>
<p>
To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>.
</p>
<p>
You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&clcid=0x409"
title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
</p>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</asp:Content>
server
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
namespace GetMethodInfo
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string param = "";
//获取参数
if (!String.IsNullOrEmpty(HttpContext.Current.Request["param"]))
{
param = HttpContext.Current.Request["param"];
}
//清空缓冲区
Response.Clear();
//将字符串写入响应输出流
Response.Write("请求的方式为:" + Request.HttpMethod.ToUpper() + "; 传递过来的参数为:" + param);
//将当前所有缓冲的输出发送的客户端,并停止该页执行
// Response.End();
string fileLoc = @"d:\sample1.txt";
FileStream fs = null;
if (!File.Exists(fileLoc))
{
using (fs = File.Create(fileLoc))
{
using (StreamWriter sw = new StreamWriter(fileLoc))
{
sw.Write(param);
}
}
}
Label1.Text = param+" "+DateTime.Now.ToString();
// Response.End();
}
}
}
<script src="js/mui.min.js"></script>
<button onclick="GetWithCallback()">测试jquery.get</v></button><br/>
<button onclick="PostWithCallback()">测试jquery.post</v></button><br/>
<script>
//测试get,使用回调函数
//注意:get()方法提供了回调函数(callback),该函数有三个参数,分别代表请求返回的内容、请求状态和XMLHttpRequest对象
function GetWithCallback() {
$.get("http://222.178.71.253:8033/Default.aspx", { "param": "TestGet-Callback" }, function (responseText, textStatus, XMLHttpRequest) {
$("#result").html("回调函数在起作用,结果:" + responseText);
});
}
//测试post,使用回调函数
function PostWithCallback() {
$.post("http://222.178.71.253:8033/Default.aspx", { "param": "TestPost-Callback" }, function (responseText, textStatus, XMLHttpRequest) {
$("#result").html("回调函数在起作用,结果:" + responseText);
});
}
</script>
.NET side
client
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="GetMethodInfo._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Welcome to ASP.NET!
</h2>
<p>
To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>.
</p>
<p>
You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&clcid=0x409"
title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
</p>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</asp:Content>
server
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
namespace GetMethodInfo
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string param = "";
//获取参数
if (!String.IsNullOrEmpty(HttpContext.Current.Request["param"]))
{
param = HttpContext.Current.Request["param"];
}
//清空缓冲区
Response.Clear();
//将字符串写入响应输出流
Response.Write("请求的方式为:" + Request.HttpMethod.ToUpper() + "; 传递过来的参数为:" + param);
//将当前所有缓冲的输出发送的客户端,并停止该页执行
// Response.End();
string fileLoc = @"d:\sample1.txt";
FileStream fs = null;
if (!File.Exists(fileLoc))
{
using (fs = File.Create(fileLoc))
{
using (StreamWriter sw = new StreamWriter(fileLoc))
{
sw.Write(param);
}
}
}
Label1.Text = param+" "+DateTime.Now.ToString();
// Response.End();
}
}
}
相关文章推荐
- android日常开发经验总结60条
- 【java】微信开发后台官方后台配置篇
- [Android] Activity之間如何透過Intent傳遞複雜結構的data
- 适配iOS9(ATS问题)
- 外媒评黑莓推 Android 手机:自取其辱
- 苹果开发者账号(公司级)和邓白氏编码(D-U-N-S)申请记录(2015.06)
- Android L+ Theme 与 Toolbar 实例
- Android数据传递方法汇总
- JMX之ObjectName
- 解读Unity中的CG编写Shader系列六(漫反射)
- Xamarin iOS教程之进度条和滚动视图
- Android Volley完全解析(一),初识Volley的基本用法
- 解读Unity中的CG编写Shader系列五(理论知识)
- 手机号码去掉‘86’或‘+86’及点击备注崩溃解决办法
- Swift学习笔记系列——(1)操作符
- IOS手势解锁
- Android 工具类(将 dp 转成 px 获取屏幕的高度/宽度 判断android SDK 版本是否大于等于5.0)
- Android图片上传(头像裁切+原图原样)
- Swift语言IOS8开发战记27 Sketch初探
- IOS-TextField知多少