Home  >  Article  >  Backend Development  >  javascript - ajax value transfer always passes the last value of the obtained data

javascript - ajax value transfer always passes the last value of the obtained data

WBOY
WBOYOriginal
2016-08-31 08:54:501077browse

ajax value transfer can only transfer the last value of the data, or it is a loop. The loop problem is solved and only the last value can be passed.
javascript - ajax value transfer always passes the last value of the obtained data

z is the post ID set by me

Reply content:

ajax value transfer can only transfer the last value of the data, or it is a loop. The loop problem is solved and only the last value can be passed.
javascript - ajax value transfer always passes the last value of the obtained data

z is the post ID set by me

When the click callback is executed, the loop has finished running, z must be allTopic.length+1, you can use something like

<code>for(var i=0;i<length;i++){
  $('test').click(function(i){
    return function(){
      $.ajax()//use i
    }
  }(i))
}
</code>

Solution

Why don’t you just concatenate the ID you want to pass into a string or process it into an array, and pass the value in one go? It consumes too much to request the server every time!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn