[英]Equivalent Callback function for “$.getJSON(”myurl“,response);”?
$.getJSON( "myurl", response);
What would the equivalent callback function version of the above look like? 上面的等效回调函数版本是什么样的? I've tried...
我试过了...
$.getJSON("myurl",function(data){
//manipulate data
return data;
});
but it doesn't appear to produce the same result. 但似乎不会产生相同的结果。
I'm working with JQuerys AutoSuggest library and attempting to manipulate the response I receive back from my server before sending it on. 我正在使用JQuerys AutoSuggest库,并尝试在发送之前处理从服务器收到的响应。
$.getJSON ("myurl", function (data)
{
// manipulate data
response (data);
});
In the first case, you pass data that are sent to the server. 在第一种情况下,您传递了发送到服务器的数据。 In the second case, you pass a success callback.
在第二种情况下,您传递一个成功回调。 There is no way of making an "equivalent callback version" to the first usage.
无法为首次使用制作“等效的回调版本”。 See jQuery.getJSON .
参见jQuery.getJSON 。
The callback will be the same but you can manipulate data in different ways, for example: 回调将是相同的,但是您可以通过不同的方式来操作数据,例如:
As you specified two types, look case 1 and 2 当您指定了两种类型时,请看案例1和2
case 1: 情况1:
//start and receive callback
function send()
{
var v = $("element").attr("value");
$.getJSON("page.php",{ v:v }, responseData);
return false;
}
//manipulate callback data
function responseData(data)
{
$("#results").html("Name: " + data.name + "<br/>" + "Lastname: " + data.lastname);
}
case 2: 情况2:
$.getJSON ("page.php", function (data)
{
$("#results").html("Name: " + data.name + "<br/>" + "Lastname: " + data.lastname);
});
Hope this helps. 希望这可以帮助。
Regards. 问候。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.