我在javascript里面调用一个jquery ajax函数很多次循环我的looop体在执行jquery ajax之后执行请给我解决方案。 [英] i call a jquery ajax function many time in javascript inside for loop my looop body before execute after jquery ajax call please give me solution .

查看:68
本文介绍了我在javascript里面调用一个jquery ajax函数很多次循环我的looop体在执行jquery ajax之后执行请给我解决方案。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,





请给我解决方案:



我的问题是:



  for  var  i =  0 ; i< 5; i ++){

var a = i;
// 这里有一些java脚本代码;
$ .ajax( {

url:
类型:
dataType:
成功:function(){ // 代码代码在最后一次,也是最后一次触发。},
错误:function(){}
});

}

解决方案

.ajax({

url:
类型: < span class =code-string>,
dataType:
成功:function(){ // 代码代码在上次和最后一次触发。} ,
错误:function(){}
});

}


目前尚不清楚你在问什么;这不是一个问题,但是 - 很明显你的代码是错误的:在 success 函数实现下,你尝试使用类似于对象属性定义语法的东西错误: function(){},在函数体块{}下无效,只能在对象定义块下有效。它抛出以下异常:

 SyntaxError:
函数语句需要名称

(异常详细信息可能取决于浏览器。)



因为这是一个语法错误,你甚至无法抓住它,就像你通常可以做其他异常一样;它使你的整个脚本不存在。我不知道你怎么能观察到代码是在最后一次,也是最后一次被解雇以及它可能意味着什么。有关处理词汇错误的更多详细信息,请参阅我的文章中的部分: JavaScript Calculator, 5 。处理词法错误



但是,你应该更好地修复语法。只需更全面地了解jQuery Ajax的用法:

http://api.jquery.com/jquery.ajax [ ^ ],

http://api.jquery.com/category/ajax [ ^ ]。



-SA

Dear Sir ,


Please give me solution :

My problem is :

for (var i =0; i<5;i++){

    var a =i;
    //like this some java script code here ;
    $.ajax({
    
    url:"",
    type:"",
    dataType:"",
    success:function(){ //code code is fired in last and only last time.},
    error:function(){}
    });

}

解决方案

.ajax({ url:"", type:"", dataType:"", success:function(){ //code code is fired in last and only last time.}, error:function(){} }); }


It's not clear what are you asking about; and this is not a question, but — it's apparent that your code is wrong: under the success function implementation, you try to use something similar to object property definition syntax "error:function(){}", which is invalid under the function body block "{}", could only be valid under the object-definition block. It throws the following exception:

SyntaxError:
function statement requires a name

(Exception detail may depend on the browser.)

As this is a syntax error, you could not even catch it as if you normally could do with other exceptions; it makes your whole script defunct. I have no idea how could you observe "code code is fired in last and only last time" and what it could possibly mean. For further detail on dealing with lexical errors, please see the section in my article: JavaScript Calculator, 5. Handling Lexical Errors.

However, you should better just fix the syntax. Just look more thoroughly at jQuery Ajax usage:
http://api.jquery.com/jquery.ajax[^],
http://api.jquery.com/category/ajax[^].

—SA


这篇关于我在javascript里面调用一个jquery ajax函数很多次循环我的looop体在执行jquery ajax之后执行请给我解决方案。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆