Hello. I need to insert a variable in the URL.

Here is the script:

<script> function testa(el) { var alink = $(el).serialize(); $.ajax({ type: 'POST', url: 'test.php', data: alink, success: function(data) { $("#refotv").text(data); }, }) } </script> 

And I need to do something like this:

AJAX

 var id = $(el).text('#div'); url: 'test.php?id='+id, 

html

 $vv = mysql_query("SELECT * FROM test"); while ($v = mysql_fetch_array($vv)) { echo "<div id='refotv'>"; echo "<a onClick='testa(this);'>".$v[text]."</a><br />"; echo "<div id='div'>".$v[id]."</div><br />"; echo "</div>"; } 

Displays 5 lines:

 Текст 1 1 Текст 2 2 Текст 3 3 Текст 4 4 Текст 5 5 

When clicking on the text, it is necessary that it processed exactly the line that it selected and sent via var id = ... , and gave the answer in #refotv in the line in which it was clicked.

    1 answer 1

    Inside the loop, remove the div id='div', div id="refotv" , write classes instead, like:

     div class="div", div class="revotf" ,или даже аттрибуты data-[] 2)<div class='refotv'> <a onClick='testa(this);'>".$v[text]."</a><br /> <div class='div'>".$v[id]."</div><br /> </div> .............. function testa(el){ $link = $(el); $id = $link.closest('.refotv').find('.div'); $.post('url.php',$id,function(res){ $link.closest('.refotv').html(res); }); } 
    • How to display class='div' - cnofss in url.php