jquery ajax 开发手记

1.json解析的格式要求更严格了,必须全部加引号,否则无法识别

{"result":"false"}

2.ashx如果要使用Session需要继承接口IRequiresSessionState

3.jq mobile跳转页面的时候只是把第一个data-role=“page”的标记内容放入dom容器,所以js脚本都会无效,决绝方法如下:1,把js代码放入page标签里。2,打包js代码到整个文件,在主页面引用,后面的页面都有效

4.jquery mobile中用ajax动态刷新控件,添加完后一定要记得在AJAX中加入刷新函数,这玩意弄了我半天,代码如下

$.post("GetCategory.ashx", function (data, status) {

if (status == "success") {

if (data.result == "请重新登录") {

alert("请重新登录");

return;

}

$.each(data, function (i, n) {

// var shtml = "

" + n.Category + "

";

var shtml = "

" + n.Category + "

"

$("#CategoryList").append(shtml);

});

}

$("#CategoryList").listview("refresh");

5.jquery选择器中带参数的选择

$("#"+n.foodCategoryId)

6.如果出现cannot call methods on listview prior to initialization; attempted to call method 'refresh'

这个问题,就在refresh之前加上$("#page").trigger("create");

7.缓存页面

保留所有访问过的页面

$.mobile.page.prototype.options.domCache = true;

缓存特定的页面

pageContainerElement.page({ domCache: true });

8.界面传参数

需要从a页面的连接跳转到B页面如下:

<a href="dsadsadsadsad?asd=dsa">~!~!~</a>这样在B页面如果用pageinit的话地址没有变,获取不到参数,所以在页面函数上改为pagebeforeshow就可以了

9.ajax如果用post提交参数,asp.net里面用context.Request.Form获取参数。如果用get方式提交参数,则用QueryString来获取参数

posted @ 2013-09-24 00:23  leestar54  阅读(246)  评论(0编辑  收藏  举报