sencha touch读取jsonp数据主要依靠Ext.data.JsonP组件,在mvc的store文件中定义代码如下:

Ext.define('eparkapp.store.ParksNearby',{
extend:'Ext.data.Store',
requires: ['Ext.data.JsonP'],
config:{
model: 'eparkapp.model.Park',
autoLoad: true,
proxy: {
type: 'jsonp',
url: 'http://192.168.1.103/androidserv/PublicAppServ.asmx/ListNearInfo',
reader:{
type: 'json',
rootProperty: 'data'
},
extraParams: {
userId: 'll',
lng: '123',
lat: '39',
key: 'abc123'
},
callbackKey: 'callback'
},
sorters: [{ property: 'Range', direction: 'ASC'}]
}
});

其中重要的是url的写法,.asmx后增加webservice的方法名,传给webservice的参数使用extraParams配置项。另外callbackKey一定要加上,值可设置为默认的callback。

webservice的写法

using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Serialization;
using System.Web.Script.Services; namespace MobileServ
{
/// <summary>
/// PublicAppServ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
[System.Web.Script.Services.ScriptService]
public class PublicAppServ : System.Web.Services.WebService
{ #region 服务 [WebMethod(Description = "获得测试数据的列表")]
public void ListNearInfo(string userId, string lng, string lat, string key)
{
HttpContext.Current.Response.ContentType = "application/json;charset=utf-8";
string jsonCallBackFunName = "callback";
if (HttpContext.Current.Request.Params["callback"]!=null)
jsonCallBackFunName = HttpContext.Current.Request.Params["callback"].ToString();
string result = string.Empty;
if (key == ConfigurationManager.AppSettings["WSKey"])
{
List<ParkInfo> lisPark = GetData();
result = "{success: true,data:[";
for (int i = ; i < lisPark.Count; i++)
{
result += "{";
result += "Name:'" + lisPark[i].Name + "'";
result += ",Address:'" + lisPark[i].Address + "'";
result += ",Range:" + lisPark[i].Range;
result += ",Price:" + lisPark[i].Price;
result += ",Count:" + lisPark[i].Count.ToString();
result += "}";
if (i < lisPark.Count - )
result += ",";
}
result += "]}";
}
HttpContext.Current.Response.Write(string.Format("{0}({1})", jsonCallBackFunName, new JavaScriptSerializer().Serialize(result))); } private List<ParkInfo> GetData()
{
List<ParkInfo> lisPark = new List<ParkInfo>();
ParkInfo pinfo1 = new ParkInfo();
pinfo1.Name = "测试路1";
pinfo1.Address = "测试地址1";
pinfo1.Range = "2.5";
pinfo1.Price = "";
pinfo1.Count = "";
lisPark.Add(pinfo1);
ParkInfo pinfo2 = new ParkInfo();
pinfo2.Name = "测试路2";
pinfo2.Address = "测试地址2";
pinfo2.Range = "3.2";
pinfo2.Price = "";
pinfo2.Count = "";
lisPark.Add(pinfo2);
ParkInfo pinfo3 = new ParkInfo();
pinfo3.Name = "测试路3";
pinfo3.Address = "测试地址3";
pinfo3.Range = "3.2";
pinfo3.Price = "";
pinfo3.Count = "";
lisPark.Add(pinfo3);
return lisPark;
} #endregion 服务
}
}

需要注意的是,webservice通过HttpContext.Current.Request.Params["callback"]来读取sencha touch从客户端发来的跨域请求的回调函数名callback。再把这个函数名加入到返回的json之前。实现客户端的跨域读取。

webservice的web.config配置节system.web下一定要加上如下配置项,否则sencha touch无法读取webservice的数据。

<webServices>
<protocols>
<add name="HttpPost"/>
<add name="HttpGet"/>
</protocols>
</webServices>

一切配置完成后,数据就能在view中展现出来。

sencha touch结合webservice读取jsonp数据详解的更多相关文章

  1. InheritableThreadLocal类原理简介使用 父子线程传递数据详解 多线程中篇(十八)

      上一篇文章中对ThreadLocal进行了详尽的介绍,另外还有一个类: InheritableThreadLocal 他是ThreadLocal的子类,那么这个类又有什么作用呢?   测试代码 p ...

  2. linux驱动由浅入深系列:高通sensor架构实例分析之三(adsp上报数据详解、校准流程详解)【转】

    本文转载自:https://blog.csdn.net/radianceblau/article/details/76180915 本系列导航: linux驱动由浅入深系列:高通sensor架构实例分 ...

  3. 利用rtklib处理GPS以及北斗数据详解

    利用rtklib开源代码处理GPS以及北斗数据详解 在GNSS领域最基础的工作是这些GNSS系统的定位工作,对于绝大多数研究者,自己着手完成这些工作是一个"鸡肋":完全独立设计的话 ...

  4. android bundle存放数据详解

    转载自:android bundle存放数据详解 正如大家所知道,Activity之间传递数据,是将数据存放在Intent或者Bundle中 例如: 将数据存放倒Intent中传递: 将数据放到Bun ...

  5. MySQL数据库使用mysqldump导出数据详解

    mysqldump是mysql用于转存储数据库的实用程序.它主要产生一个SQL脚本,其中包含从头重新创建数据库所必需的命令CREATE TABLE INSERT等.接下来通过本文给大家介绍MySQL数 ...

  6. 【笔记】Pandas分类数据详解

    [笔记]Pandas分类数据详解 Pandas  Pandas分类数据详解|轻松玩转Pandas(5) 参考:Pandas分类数据详解|轻松玩转Pandas(5)

  7. Farseer.net轻量级开源框架 入门篇:添加数据详解

    导航 目   录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 入门篇: 分类逻辑层 下一篇:Farseer.net轻量级开源框架 入门篇: 修改数据详解 ...

  8. Farseer.net轻量级开源框架 入门篇:修改数据详解

    导航 目   录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 入门篇: 添加数据详解 下一篇:Farseer.net轻量级开源框架 入门篇: 删除数据详解 ...

  9. Farseer.net轻量级开源框架 入门篇:删除数据详解

    导航 目   录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 入门篇: 修改数据详解 下一篇:Farseer.net轻量级开源框架 入门篇: 查询数据详解 ...

随机推荐

  1. eps图片中有中文乱码的问题

    一般的,如果matlab中的fig图片中有中文,直接saveas为eps,eps再插入latex后会出现乱码. 解决的办法为: (1) *.fig利用‘file--print’保存为*.pdf (2) ...

  2. flutter演示项目:游侠客户端

    使用flutter实现的游侠客户端. 还有一些页面没写,最主要的问题是无法解析html富文本. https://github.com/axel10/flutter_ali213_client_demo

  3. HDU 1556 Color the ball【差分数组裸题/模板】

    N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一 ...

  4. Educational Codeforces Round 30 A[水题/数组排序]

    A. Chores time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  5. Django项目静态文件加载失败问题

    在我们平时的开发过程中,为了方便调试程序,我们都是打开开发者模式,即Debug=True,当我们正式上线的时候肯定就需要把开发者模式关掉,用uwsgi部署上去以后,突然发现我们平时辛苦做的项目的静态文 ...

  6. HDU 2256 Problem of Precision (矩阵快速幂)(推算)

    Problem of Precision Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  7. 12、Django实战第12天:课程机构列表页数据展示

    今天完成的是课程机构列表页.... 1.启动服务,进入xadmin后,添加5个城市信息用作测试数据 2.添加课程机构,其中有一项要上传封面图的地方要注意 封面图上传路径是我们在models中设置好的 ...

  8. VS code 的变量设定

    文档来自https://code.visualstudio.com/docs/editor/variables-reference 预定义的变量有: ${workspaceFolder} - the ...

  9. luogu P1802 5倍经验日

    题目背景 现在乐斗有活动了!每打一个人可以获得5倍经验!absi2011却无奈的看着那一些比他等级高的好友,想着能否把他们干掉.干掉能拿不少经验的. 题目描述 现在absi2011拿出了x个迷你装药物 ...

  10. [Codeforces 8E] Beads

    Brief Intro: 将所有n位二进制串中满足字典序不大于其逆序串,取反串,逆序取反串中按字典序排序的第m个输出 n<=50 Algorithm: 首次接触数位DP的题目 根据数据范围,我们 ...