Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make jQuery form submission not refresh the page but add the content - AJAX like?
    primarykey
    data
    text
    <p>In my <code>$('#my_form').submit(function()</code> I have a code that should add some more information on selected song from <code>my_form</code> form. I would like it to be able to change content of <code>info_table</code> on each form submission (if different song is marked). How can I do this ? If I leave <code>return false;</code> then the page won't reload anymore.</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" &gt;&lt;/script&gt; &lt;form id="my_form"&gt; &lt;table border='2' id="my_table"&gt;&lt;/table&gt; &lt;input type="submit" value="Show song info" id="submit_button"&gt; &lt;/form&gt; &lt;table border='2' id="info_table"&gt;&lt;/table&gt; &lt;script&gt; var my_xml; $(document).ready(function() { $.get("songs_2.xml", function(d){ my_xml = d; //$('body').append("&lt;table border='2'&gt;"); var html = ""; var i = 0; $(d).find('song').each(function(){ var $song = $(this); var title = $song.find('title').text(); var artist = $song.find('artist').text(); var cover = $song.find('cover').text(); var id = $song.find("id").text(); html += "&lt;tr&gt;&lt;td&gt;"+id+"&lt;/td&gt;&lt;td width='120'&gt;&lt;b&gt;" + artist + " &lt;/b&gt;&lt;/td&gt;&lt;td width='150'&gt; " + title + "&lt;/td&gt;&lt;td&gt;"; html += "&lt;img src='" + cover + "' height='50' width='50'/&gt;&lt;/td&gt;&lt;td&gt; &lt;input type='radio' name='which' value='"+id+"'&gt;&lt;/td&gt;&lt;/tr&gt;" ; $('#my_table').append($(html)); html = "" i++; }); }); }); $('#my_form').submit(function() { var i = $("#my_form input[type='radio']:checked").val(); $.get("songs_2.xml", function(d){ my_xml = d; //$('body').append("&lt;table border='2'&gt;"); var html = ""; var i = 0; $(d).find('song').each(function(){ var $song = $(this); var title = $song.find('title').text(); var artist = $song.find('artist').text(); var cover = $song.find('cover').text(); var id = $song.find("id").text(); $('#info_table').html("&lt;tr&gt;&lt;td&gt;" + ALOTOFINFO + "&lt;/td&gt;&lt;/tr&gt;"); }); }); return false; }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload