将参数传递给 jQuery 的 .load() 的最佳方式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/263962/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 08:50:58  来源:igfitidea点击:

Best way to pass parameters to jQuery's .load()

jqueryajax

提问by

Is there a difference in passing parameters to .load

传递参数有区别吗 .load

$("#myDiv").load("myScript.php?var=x&var2=y&var3=z")

vs

对比

$("#myDiv").load("myScript.php", {var1:x, var2:y, var3:z})

Also, is there a size limit to how much .loadcan handle? Can myScript.phpreturn a couple hundred rows of data without issue?

另外,有多少.load可以处理的大小限制?可以 myScript.php毫无问题地返回几百行数据吗?

回答by Davide Gualano

In the first case, the data are passed to the script via GET, in the second via POST.

在第一种情况下,数据通过 GET 传递给脚本,在第二种情况下通过 POST 传递给脚本。

http://docs.jquery.com/Ajax/load#urldatacallback

http://docs.jquery.com/Ajax/load#urldatacallback

I don't think there are limits to the data size, but the completition of the remote call will of course take longer with great amount of data.

我认为数据大小没有限制,但是如果数据量很大,远程调用的完成当然需要更长的时间。

回答by Farshid Saberi

As Davide Gualano has been told. This one

正如大卫·瓜拉诺所说。这个

$("#myDiv").load("myScript.php?var=x&var2=y&var3=z")

use GET method for sending the request, and this one

使用 GET 方法发送请求,而这个

$("#myDiv").load("myScript.php", {var:x, var2:y, var3:z})

use POST method for sending the request. But any limitation that is applied to each method (post/get) is applied to the alternative usages that has been mentioned in the question.

使用 POST 方法发送请求。但是,适用于每种方法(post/get)的任何限制都适用于问题中提到的替代用法。

For example: url length limits the amount of sending data in GET method.

例如: url 长度限制 GET 方法发送数据量。