小编Nik*_*ikG的帖子

将变量传递给jQuery ajax成功或错误函数

我使用JQuery $ .ajax循环一组JSON URL并将结果下载到数组中.一些URL返回404 - 我正在处理并显示为div消息.

但是,我似乎无法传递URL,更确切地说,它总是只传递数组中的最后一个URL.

我假设这是因为ajax是异步的并且需要更长的时间来完成,但我不确定如何确保只有当前的JSON url(或变量)显示在SUCCESS或ERROR上

我的代码:

 // For every URL loop through 'baseitems' array
 for (var i = 0; i < baseitems.length; i++) {

  // This is where I'm hoping to store the current URL as a variable to pass to the end-user on Success or Error
  var caturl = baseURL + "/" + baseitems[i];

  // Get the data via JSON
  $.ajax({
    type: "GET",
    url: caturl,
    dataType: "json",
    async: true, // set so that the variables …
Run Code Online (Sandbox Code Playgroud)

ajax jquery json

9
推荐指数
1
解决办法
1万
查看次数

Node.js中的异步OR步骤

我无法让我的异步代码与node.js一起工作

尝试同步和步骤库 - 代码只返回第一个函数(似乎没有完成其余的).我究竟做错了什么?

谢谢!

var step = require('step');
step(
function f1(){
        console.log('test1');
},
function f2(){
        console.log('test2');
},
function finalize(err) {
    if (err) { console.log(err);return;}
    console.log('done with no problem');
  }
);
Run Code Online (Sandbox Code Playgroud)

或这个:

var async = require('async');
async.series([
function f1(){
        console.log('test1');
},
function f2(){
        console.log('test2');
},
function finalize(err) {
    if (err) { console.log(err);return;}
    console.log('done with no problem');
  }
]);
Run Code Online (Sandbox Code Playgroud)

asynchronous node.js

7
推荐指数
1
解决办法
6313
查看次数

标签 统计

ajax ×1

asynchronous ×1

jquery ×1

json ×1

node.js ×1