Sooze Sooze - 2 months ago 5
jQuery Question

Can I change onscreen HTML when a JSON/AJAX response is successful?

Summary:
I have a listing of helpdesk type requests.
When a document is uploaded to an incident on the list by clicking a folder icon, the icon changes to reflect the upload.
I would like a Status (M or D) on that same row to change at that same time.




In other words:
Using Json an ajax call is made and a class of a specific .tr element(.td) is changed with the response.
That all works great.

I'm placing my logic just after the change because in that same .tr I need a different element(.td) to change also.

I need the html in a .td to 'flip'. In other words, if the data in the element is an "M" I want it to change to a "D" and if it's a "D" I want it to change to an "M".

I CANNOT get just ONE Row to change - They ALL Change.

This is VERY abbreviated.
HTML:

<table>
<tr>
<td id="StatusID"><span title="MFTA ACTIVE" class="status"><font color="RED">M</font></span></td>
<td class="tar"> 003430</td>
<td class="comments"></td>
</tr>
</table>


I'm showing ONLY the new JQuery...

// Flip the status if this is an open TAR
var dspStatus =$('.tar:contains(' + tarNo + ')').parents('tr').find('.status').text();
if (dspStatus == "M") {
dspStatus = "D";
}
else if (dspStatus == "D") {
dspStatus = "M";
}
$('.tar:contains(' + tarNo + ')').parents('tr').find('.Status').html(dspStatus);


Of course the fiddle wont run but it helped me with a couple other things :https://jsfiddle.net/qbw30oLz/8/
(To see move of the Java script: https://jsfiddle.net/SJSooze/7z0xs0v1/3/)

Pat Pat
Answer

check this out !! You can directly use the class status and if you do not use an else condition, if your dspStatus is M then eventually it becomes D and then again it would be changed to M as it is D. So better use else if or else.

  var dspStatus = $('.status').text();
  if (dspStatus == "M") {
    dspStatus = "D";
  }
  else if (dspStatus == "D") {
    dspStatus = "M";
  }
  $('.status').text(dspStatus );
Comments