weixin_33690367 2015-04-20 04:46 采纳率: 0%
浏览 277

通过ajax进行递归调用

i am using the following code to recursively call through ajax.

function ajax_pay(i)
{
    var opt=document.getElementById("fpayee").options;
        payid=opt[i].value;
        alert(i);
       if(payid==""){return;}

    alert(payid);
     if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } 
        else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 &&  xmlhttp.status == 200) {


       document.getElementById("hint").innerHTML=i;
        i++;   
        ajax_pay(i); 


            }
        }
        xmlhttp.open("GET","closeup.php?pid="+payid,true);
        xmlhttp.send();

}

here fpayee is a combobox and i am initialising the recursion through ajax_pay(0);

But the problem is it runs only for once. please help;

  • 写回答

1条回答 默认 最新

  • weixin_33724659 2015-04-20 15:39
    关注

    i Got it. I was calling it wrongly.this the write way to do

     <button type="button" onclick="ajax_pay(0)">
    
    评论

报告相同问题?