通过AJAX发布数据

时间:2014-02-27 05:21:07

标签: jquery ajax json

任何人都可以向我解释下面的代码如何工作,我想知道每个字段的重要性以及每个字段的可能值。

另外请解释一下它是如何工作的。提前致谢

$.ajax({
 type: "POST",
 url: "Controller/View",
 data: data,
 contentType: "application/json; charset=utf-8",
 dataType: "json"
});

1 个答案:

答案 0 :(得分:0)

您的代码传递并反对$ .ajax()函数,该函数读取对象并执行以下操作:

type - 将您的HTTP请求方法设置为POST。

url - 修改请求的网址部分

数据 - 填写请求正文并按照

设置Content-Length标头

contentType - 在HTTP请求中设置Content-Type标头,描述请求正文包含的内容类型。

dataType - 设置HTTP请求的Accept标头,描述您希望在服务器响应正文中找到的数据类型。

最后,您的HTTP请求可能如下所示:

POST Controller/View HTTP/1.1
Content-Type: application/json; charset=utf-8
Aceept: application/json
Content-Length: {length of data goes here}
{data itself goes here}

有关此功能的更多信息,您可以查看JQuery文档:http://api.jquery.com/jQuery.ajax/

相关问题