Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jqueryajax调用函数_Javascript_Jquery_Ajax_Function_Call - Fatal编程技术网

Javascript jqueryajax调用函数

Javascript jqueryajax调用函数,javascript,jquery,ajax,function,call,Javascript,Jquery,Ajax,Function,Call,我希望能够从“on success”区域调用函数,而不必将代码放在该区域。我将使用这段代码两次,因此我试图找出如何将它放在jQuery.ajax()函数之外 $.ajax({ type: "GET", url: "ws/getweather.ashx?zip=32751", dataType: "xml", success: function (xml){ weatherize(xml); }, error: function (xml) { alert("Unrecognize

我希望能够从“on success”区域调用函数,而不必将代码放在该区域。我将使用这段代码两次,因此我试图找出如何将它放在jQuery.ajax()函数之外

$.ajax({
type: "GET",
url: "ws/getweather.ashx?zip=32751",
dataType: "xml",
success: function (xml){
    weatherize(xml);
},
error: function (xml) {
    alert("Unrecognized Region. Please try again.");
}
});
这是我目前的代码:

$.ajax({
  type: "GET",
  url: "ws/getweather.ashx?zip=" + vZip,
  dataType: "xml",
  success: function (xml) {
  $(xml).find('weather').each(function () {
     // Load New Data
     ...
});
},
  error: function (xml) {
    alert("Unrecognized Region. Please try again.");
  }
});       
因此,与其拥有

function (xml) {
  $(xml).find('weather').each(function () {
     // Load New Data
     ...
});
我想输入另一个函数的名称,并将xml传递给该函数。这样我就可以让其他事件调用同一组代码

提前谢谢

更新===================================================

感谢迈克·理查兹的及时回复。我在下面包含了确切的语法,因为我必须添加一些细节才能使其工作……这意味着,将XML传递给另一个函数

$.ajax({
type: "GET",
url: "ws/getweather.ashx?zip=32751",
dataType: "xml",
success: function (xml){
    weatherize(xml);
},
error: function (xml) {
    alert("Unrecognized Region. Please try again.");
}
});
下面是我的另一个函数

function weatherize(xml) {
  $(xml).find('weather').each(function () {
// Load New Data
...
})
};

您只需为该参数传入一个函数:)

然后,还有一些:

function successFunction(data) {
  // Do Something
}

您只需为该参数传入一个函数:)

然后,还有一些:

function successFunction(data) {
  // Do Something
}

谢谢,迈克,成功了。我发布了上面的确切语法。祝你一周愉快!谢谢,迈克,成功了。我发布了上面的确切语法。祝你一周愉快!嘿,联络人,很高兴能成功。另外,请注意,您不需要包装器函数。你只需做
success:weatherize,
Hey Contact,很高兴成功了。另外,请注意,您不需要包装器函数。您只需执行
success:weatherize,