ajax - jQuery merge loop returns? -


i'm trying loop results 1 using ajax send of them once

here's code more explanation :

<div class='item'>name1</div> <div class='item'>name2</div> 

jquery

$(".item").each(function(){   var value = $(this).text(); }); 

^ returns both name1 , name2 not @ once, need merge them can send them both ajax request

this how want ( invalid code )

$(".item").each(function(){   var value1 = $(this[0]).text(); // tho dont wanna use numbers, wanna of them   var value2 = $(this[1]).text();    var final = value1 + value2; // name1name2 });     $.get('go.php', {items : final}, function(... 

this invalid code ^ give example of how should end with
first problem merging, don't know how should be,
, second want call var final outside loop wont repeat request

fiddle: http://jsfiddle.net/iambriansreed/wf3sf/

try:

var final = []; $(".item").each(function(){    final.push(this.innerhtml); }); 

or:

var final = $('.item').map(function() {     return this.innerhtml; }).get(); 

or mentioned in comments:

var items = $('.item').map(function() {     return this.innerhtml; }).get();  var final = "something1" + items[0] + "something2" + items[1]; 

or this:

$('.item').each(function(i) {     window['value'+(i+1)] = this.innerhtml; });  var final = "something1" + value1 + "something2" + value2;  $.get('go.php', {'items' : final }, function(... 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -