显示标签为“Ajax”的博文。显示所有博文
显示标签为“Ajax”的博文。显示所有博文

2011年11月29日星期二

Google Maps JavaScript API 几种事件(event)的说明

当移动或放大缩小google maps时,将会产生zoom_changed、center_changed、bounds_changed、dragend等各种事件。通过下面的html代码可以测试这些事件何时发生,以及发生的先后顺序。

运行html文件后可得出下面的结论:

  1. 当移动地图时,center_changed和bounds_changed事件会不断触发,一直到移动结束。所以如果需要在视图改变时利用Ajax方式获取数据时千万不要绑定到bounds_changed(或center_changed)事件,因为这样会在移动一次地图时触发多次bounds_changed事件,导致多次重复的Ajax请求

  2. 事件触发的顺序 center_changed -- zoom_changed -- bounds_changed , 当center_changed事件发生时不一定能正确通过getBounds()函数获取视图边界

  3. dragend事件在拖动结束时触发,此时由于地图可能还在移动,所以还可能继续触发center_changed和bounds_changed事件







Google Maps JavaScript API v3 Example: Event Simple

















2011年8月20日星期六

jQuery.post()函数的使用方法

函数原型: jQuery.post( url, [data], [success(data, textStatus, jqXHR)], [dataType] )
参数说明:
url 请求发送的地址
data 随请求发送的一个关联对象或者一个字符串
success(data, textStatus, jqXHR) 指定请求成功时执行的一个callback函数
dataType 预期从服务器接收的数据类型. 默认: 智能判断 (xml, json, script, or html).

返回值类型:jqXHR

此函数是下面函数的简写形式

$.ajax({
type: 'POST',
url: url,
data: data,
success: success,
dataType: dataType
});


使用示例:

$.post("test.php", { "func": "getNameAndTime" },
function(data){
console.log(data.name); // John
console.log(data.time); // 2pm
}, "json")
.success(function() { alert("second success"); })
.error(function() { alert("error"); })
.complete(function() { alert("complete"); });


关于dataType参数的详细说明
期待从服务器返回的数据类型. 如果不指定, jQuery 将基于返回结果的MIME类型 (XML MIME 类型将产生 XML, in 1.4 JSON 将产生 一个 JavaScript 对象, in 1.4 script 将执行 script, and 其他将作为字符串返回)尝试推断它. 可用的类型 (和传递给 success callback 函数第一个参数最终的结果) 是:

"xml": 返回一个可以通过jQuery解析的 XML 文档 .

"html": 把 HTML 作为普通文本返回; included script tags are evaluated when inserted in the DOM.

"script": 将返回值作为 JavaScript对待并以普通文本方式返回. Disables caching by appending a query string parameter, "_=[TIMESTAMP]", to the URL unless the cache option is set to true. Note: This will turn POSTs into GETs for remote-domain requests.

"json": 将返回值作为 JSON 对待 并返回一个 JavaScript 对象. In jQuery 1.4 JSON 数据使用严格的方式解析; 任何格式异常的JSON 都被拒绝并抛出一个parse error. (更多关于正确的JSON格式请参考 json.org 网站.)

"jsonp": Loads in a JSON block using JSONP. Adds an extra "?callback=?" to the end of your URL to specify the callback. Disables caching by appending a query string parameter, "_=[TIMESTAMP]", to the URL unless the cache option is set to true.

"text": 普通文本字符串.

多个以空格分隔的值: 从 jQuery 1.5, jQuery 能够将从Content-Type头中得到的dataType转换为你需要的其他类型 . 例如,如果你想将一个文本返回值作为XML对待,使用 "text xml" 作为 dataType. You can also make a JSONP request, have it received as text, and interpreted by jQuery as XML: "jsonp text xml." Similarly, a shorthand string such as "jsonp xml" will first attempt to convert from jsonp to xml, and, failing that, convert from jsonp to text, and then from text to xml.

2011年1月6日星期四

WordPress中自定义more标签

wordpress是十分强大的php语言个人博客系统,安装使用都很方便,可以google一下。
下面简单谈谈more标签的使用。

我们都想在首页显示尽可能多的文章,又不想让页面太长影响用户体验,在合适的位置添加more标签是个不错的主意。
more标签是wordpress的一种html注释方式的标记,如右所示: <!--more--> 要注意字母m之前不能有空格,也就是说<!-- more--> 不是more标签,而是注释。

当添加more标签后,之后的文章内容将不会被显示,而是以一个指向单独文章的链接来表示,链接的文本默认为更多...这样的形式。

下面简单说一下修改链接默认文本的方式,比如从“更多...”改为“阅读更多内容...”

首先进入wordpress后台管理页面,展开 外观(themes) 选项卡,选择 编辑,可以看到右边有很多主题相关的文件,如index.php,page.php,header.php等,每个文件分别对应页面的一个位置。点击index.php(没有这个文件的话点击home.php),在第20行左右找到类似<?php the_content('更多...'); ?> 这一行,直接修改"更多..."为“阅读更多内容...”即可。