Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery append() profile(data from server using $.getJSON) in the same page
    primarykey
    data
    text
    <p>Stuck to display profile(data from server using <code>$.getJSON</code>) in the same page using jQuery <code>append()</code>, as I'm new to this platform. Commented out the area where I stuck,</p> <pre><code>&lt;body&gt; &lt;div id="homepage"&gt; &lt;button id="home"&gt;Home&lt;/button&gt; &lt;/div&gt; &lt;div data-role="content" id="old_content" style="text-align: center"&gt; &lt;button data-icon="arrow-d"&gt;Select Below Options&lt;/button&gt; &lt;div data-role="fieldcontain"&gt; &lt;select name="select-choice-1" id="select-choice-1"&gt; &lt;!-- &lt;option&gt;--Course--&lt;/option&gt; --&gt; &lt;option value="mba"&gt;MBA&lt;/option&gt; &lt;option value="msc"&gt;MSc&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;div data-role="fieldcontain"&gt; &lt;select name="select-choice-1" id="select-choice-2"&gt; &lt;!-- &lt;option&gt;--Country--&lt;/option&gt; --&gt; &lt;option value="India"&gt;India&lt;/option&gt; &lt;option value="United Kingdom"&gt;United Kingdom&lt;/option&gt; &lt;option value="United States"&gt;United States&lt;/option&gt; &lt;option value="China"&gt;China&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;div data-role="fieldcontain"&gt; &lt;select name="select-choice-1" id="select-choice-3"&gt; &lt;!-- &lt;option&gt;--Year--&lt;/option&gt; --&gt; &lt;option value="2010"&gt;2010&lt;/option&gt; &lt;option value="2011"&gt;2011&lt;/option&gt; &lt;option value="2012"&gt;2012&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;button id="go" data-theme="b"&gt;Go&lt;/button&gt; &lt;/div&gt; &lt;div id="new_content"&gt; &lt;/div&gt; &lt;div id="profile"&gt; &lt;/div&gt; &lt;div data-position="fixed" data-theme="b" data-role="footer" data-transition="pop"&gt; &lt;h4&gt;© 2013 example.&lt;/h4&gt; &lt;/div&gt; &lt;/div&gt; &lt;script src="http://code.jquery.com/jquery-1.9.1.min.js"&gt;&lt;/script&gt; &lt;script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="js/index.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; app.initialize(); &lt;/script&gt; &lt;script type="text/javascript"&gt; var numRecords = 5 ; var maxPage = 0 ; var pro = 0 ; $course = $('#select-choice-1').val(); $country = $('#select-choice-2').val(); $year = $('#select-choice-3').val(); $(document).ready(function(){ $("#go").click(function(){ $("#old_content").hide(); listStudents(0) ; }); }); function listStudents(start) { $.getJSON( "http://example.com/api.php?course="+$course+"&amp;year="+$year+"&amp;country="+encodeURIComponent($country), function( data ) { $("#new_content").show(); $("#new_content").html(''); maxPage = start + numRecords ; for(i=start;i&lt;=maxPage;i++) { $("#new_content").append("&lt;ul id='new_output_content' onclick='profile("+i+")'&gt;&lt;li&gt;&lt;img height='50px' width='50px' src="+data[i].profile_image+'/&gt;'+"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;"+data[i].name+"&lt;/li&gt;&lt;/ul&gt;&lt;br/&gt;"); } $("#new_content").prepend('&lt;button data-theme="b" style="margin-left: 100px;margin-top: 40px;text-align: center;height: 40px;width: 153px;" data-role="button" onclick="listStudents(maxPage)"&gt;Next&lt;/button&gt;'); }); } function profile(pro) { //This is where I stuck. var profile = "&lt;div id='new_profile' data-role='content' align='center'&gt;&lt;img src='"+data[pro].profile_image+"' /&gt;&lt;br /&gt;&lt;strong&gt;"+data[pro].name+"&lt;/strong&gt;&lt;br/&gt;&lt;br/&gt;Mail ID:&lt;br/&gt;&lt;strong&gt;"+data[pro].email+"&lt;/strong&gt;&lt;br/&gt;Position:&lt;br/&gt;&lt;strong&gt;"+data[pro].position+"&lt;/strong&gt;&lt;br/&gt;Course:&lt;br/&gt;&lt;strong&gt;"+data[pro].course+"&lt;/strong&gt;&lt;br/&gt;Year of Passed Out:&lt;br/&gt;&lt;strong&gt;"+data[pro].course_year+"&lt;/strong&gt;&lt;br/&gt;Country:&lt;br/&gt;&lt;strong&gt;"+data[pro].country+"&lt;/strong&gt;&lt;br/&gt;&lt;/div&gt;"; $('#profile').append(profile); } $(document).ready(function(){ $("#home").click(function(){ $("#new_content").hide(); $("#old_content").show(); }); }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I want to display the profile alone by hiding other 'id' when click particular student. Please someone help.</p>
    singulars
    1. This table or related slice is empty.
    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