Sooze Sooze - 1 year ago 56
jQuery Question

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

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.

<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>

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 :
(To see move of the Java script:

Pat Pat
Answer Source

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 );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download