Jquery ajax参数设置
参数名
类型
描述
url
String
(默认: 当前页地址) 发送请求的地址。
type
String
(默认: "GET") 请求方式 ("POST" 或 "GET"), 默认为 "GET"。注意:其它 HTTP 请求方法,如 PUT 和 Delete 也可以使用,但仅部分浏览器支持。
timeout
Number
设置请求超时时间(毫秒)。此设置将覆盖全局设置。
async
Boolean
(默认: true) 默认设置下,所有请求均为异步请求。如果需要发送同步请求,请将此选项设置为 false。注意,同步请求将锁住浏览器,用户其它操作必须等待请求完成才可以执行。
beforeSend
Function
发送请求前可修改 XMLHttpRequest 对象的函数,如添加自定义HTTP 头。XMLHttpRequest 对象是唯一的参数。
function (XMLHttpRequest) {
this; // the options for this ajax request
}
cache
Boolean
(默认: true) jQuery 1.2 新功能,设置为 false 将不会从浏览器缓存中加载请求信息。
complete
Function
请求完成后回调函数 (请求成功或失败时均调用)。参数:XMLHttpRequest 对象,成功信息字符串。
function (XMLHttpRequest, textStatus) {
this; // the options for this ajax request
}
contentType
String
(默认: "application/x-www-form-urlencoded") 发送信息至服务器时内容编码类型。默认值适合大多数应用场合。
data
Object,
String
发送到服务器的数据。将自动转换为请求字符串格式。GET 请求中将附加在 URL 后。查看 processData 选项说明以禁止此自动转换。必须为 Key/Value 格式。如果为数组,jQuery 将自动为不同值对应同一个名称。如 {foo:["bar1", "bar2"]} 转换为'&foo=bar1&foo=bar2'。
dataType
String
预期服务器返回的数据类型。如果不指定,jQuery 将自动根据 HTTP包 MIME 信息返回 responseXML 或 responseText,并作为回调函数参数传递,可用值:
"xml": 返回 XML 文档,可用 jQuery 处理。
"html": 返回纯文本 HTML 信息;包含 script 元素。
"script": 返回纯文本 JavaScript 代码。不会自动
相关文档:
A.aspx页面放一个dropdownlist,在A.aspx.cs添加: this.drpSchool.Attributes.Add("onchange", "load(this.options[this.selectedIndex].value)");
在A.aspx页面添加如下脚本:
function load(state){
var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
var oDoc = new ActiveXObject("MSXML2.DOMDocument");
......
由于安全问题的考虑,Ajax(xmlhttprequest)默认是不支持跨域调用的。比如在www.cadal.com去请求www.test.cadal.com的数据,都是不行的。
解决方案有很多,总结如下:
参考:
1.利用<script>标签
Difficult to know when the content is available, no standard methodology, can be considered a "security risk" ......
摘自:http://www.ibm.com/developerworks/library/wa-aj-jsonp1/
AJAX Same-Origin Policy(SOP) limitation:
AJAX prevents cross-domail invokation, there are several ways to by pass this limitation.
1. write a proxy on the server side. The SOP limitation only exists only on the javascript si ......
ASP.NET AJAX入门系列将会写关于ASP.NET AJAX一些控件的使用方法以及基础知识,其中部分文章为原创,也有一些文章是直接翻译自官方文档,本部分内容会不断更新。
目录
ASP.NET AJAX入门系列(1):概述
导读:作为本系列文章的开篇,简单介绍一下ASP.NET AJAX的概况及各个组成部分。
......
<html>
<head>
<title>jQuery Ajax 实例演示</title>
</head>
<script language="javascript" src="../lib/jquery.js"></script>
<script language="javascript">
$(document).ready(function ()
{
$('#send_ajax').click(function (){
&nb ......