Jump to content

lost span after jQuery ajax call


Firemankurt

Recommended Posts

The IDEA:

 

I have several spans with an IDs of  "Chunk0","Chunk1","Chunk2", etc...

 

<span id="Chunk0">Waiting...</span>
<span id="Chunk1">Waiting...</span>
<span id="Chunk2">Waiting...</span>

 

I want to give feedback to user about where in the process each "Chunk" of data is as it is processed by jQuery (Sent to the server and returned status).

 

It starts out as "waiting..."

Then as it is sent "Sending Now..."

Then when server returns result I want it to say "Sent"

 

<!--
sending = function (id)
{
$('#Chunk'+id).html( 'Sending Now...' );
$.ajax( {
type: "POST",
url: 'Paging3/ajax/paging.php',
data: {Udate:UFID,ChunkNum:id},
success: function(r){ $('#Chunk'+id).html( 'Sent' ); },
error: function(){alert('Paging Set Failed - Please check your connection.');}
});
id++;
if ($('#Chunk'+id).length) sending(id);
}

//-->

 

 

The PROBLEM:

The span changes to "Sending Now..." but the spans never change to "Sent" after the ajax call.

 

I changed the success function to see if I could debug it and found that the code below alerts "#Chunk0 NOT FOUND" every time.

 

<!--
sending = function (id)
{
$('#Chunk'+id).html( 'Sending Now...' );
$.ajax( {
type: "POST",
url: 'Paging3/ajax/paging.php',
data: {Udate:UFID,ChunkNum:id},
success: function(r){ if($('#Chunk'+id).length) {alert('#Chunk'+id+' FOUND');} else {alert('#Chunk'+id+' NOT FOUND');} $('#Chunk'+id).html( 'Sent' ); },
error: function(){alert('Paging Set Failed - Please check your connection.');}
});
id++;
if ($('#Chunk'+id).length) sending(id);
}

//-->

 

Why is jQuery not finding the span after the ajax call?

Link to comment
Share on other sites

Kinda solved it.

 

I changed to:

<!--
sending = function (id)
{
var curChunk = $('#Chunk'+id);
curChunk.html( 'Sending Now...' );
$.ajax( {
type: "POST",
url: 'Paging3/ajax/paging.php',
data: {Udate:UFID,ChunkNum:id},
success: function(r){ curChunk.html( 'Sent' ); },
error: function(){alert('Paging Set Failed - Please check your connection.');}
});
id++;
if ($('#Chunk'+id).length) sending(id);
}

//-->

 

It works and is probably more efficient but I am not totally sure why it did not before????

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.