javascript - ajax passing the json value to html header class -
i confused on how pass json variable html header tag. using codeigniter framework, got values of query in json , put in variable , works good, when tried display in header, confused how right.
all want :
this ajax query.
function showprojectdetails(projectselected) { var studentid = null; $.ajax({ url : "<?php echo site_url('manager/projects/projdetails/')?>/" + projectselected, type: "get", datatype: "json", success: function(data) { $projcode = data['project_code']; $projtitle = data['project_title']; $projdesc = data['project_desc']; $projstat = data['project_status']; $projpercent = data['project_percent']; $projadd = data['project_address']; }, error: function (jqxhr, textstatus, errorthrown) { alert('error data ajax'); } });
from html heading. want display variables of data :
<ul> <li> <h3 class="blue">$projtitle</h3> <!--span>interactions</span--></li> <li> <h3 class="purple">status:</h3> <!--span>posts</span--></li> </ul>
so assume getting data right , problem displaying on page. use jquery achieve this.
first add id attribute tags use them reference displaying...
<ul> <li> <h3 class="blue" id="projecttitle"></h3></li> <li> <h3 class="purple">status:<span id="projectstatus"></span></h3></li> </ul>
and heres ajax should like
function showprojectdetails(projectselected) { var studentid = null; $.ajax({ url : "<?php echo site_url('manager/projects/projdetails/')?>/" + projectselected, type: "get", datatype: "json", success: function(data) { $('#projecttitle').html(data['project_title']); $('#projectstatus').html(data['project_status']); //and on }, error: function (jqxhr, textstatus, errorthrown) { alert('error data ajax'); } });
Comments
Post a Comment