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

WBOY
Release: 2016-08-31 08:54:50
Original
1076 people have browsed it

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!