简体   繁体   English

数据是getJSON()回调函数中的保留变量吗?

[英]Is data a reserved variable in getJSON() callback function?

Here is the descrition of getJSON in jquery : 这是jquerygetJSON的描述:

$(selector).getJSON(url,data,success(data,status,xhr))

Here success(data,status,xhr) is a callback function when success. 这里success(data,status,xhr)是成功时的回调函数。 I often see the code below: 我经常看到下面的代码:

 $(select(.getJSON('my/url', function(data) {....});

Here variable data holds the data returned by the http server. 这里,变量data保存由http服务器返回的数据。 My question is that instead of using name data here, can I use variable name like server_data as below? 我的问题是,我可以在下面使用像server_data这样的变量名,而不是在这里使用名称data吗?

 $(select(.getJSON('my/url', function(server_data) {....});

It's a function argument name. 这是一个函数参数名称。 You can name it whatever you want, so long as it follows the valid javascript variable name format. 您可以根据需要命名,只要它遵循有效的javascript变量名称格式即可。

Ref: What characters are valid for JavaScript variable names? 参考: 哪些字符对JavaScript变量名称有效?

Edit: Also, easy enough to test without asking a question. 编辑:此外,足够容易进行测试,而无需提出问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM