SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2004
    Location
    DK
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AJAX update page

    Hi,
    I followed the video tutorials on this site - pretty good.
    I'm now able to delete records and remove the tr on he fly.
    Im also able to insert a new record i my db, i the background.
    But how do i update my page so the post shows up?

    Code:
    function ajaxUpdate()
    {
    	var xhr;
    	try
    	{
    		xhr = new XMLHttpRequest();
    	} catch (error)
    	{
    		try
    		{
    			xhr = new ActiveXObject('Microsoft.XMLHTTP');
    		} catch (error)
    		{
    			xhr = null;
    		}
    	}
    	
    	if (xhr != null)
    	{
    		var updateId = this.id.substring('update-'.length);
    
    		xhr.open('POST', './update.php?todoId=' + updateId + '', true);
    		
    		var td = this.parentNode;
    		var tr = td.parentNode;
    		tr.deleting = true;
    		td.className += " status";
    		td.innerHTML = "Updating";
    
    		xhr.onreadystatechange = function()
    		{
    			if (xhr.readyState == 4)
    			{
    				if (xhr.status == 200 || xhr.status == 304)
    				{
    		// WHAT TO DO HERE??????
    				} else
    				{
    					td.innerHTML = "Error!";
    				}
    			}
    		};
    		
    		xhr.send(null);
    				
    		return false;
    	}
    	return true;
    }

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i solved this with another ajax function which is triggered into the first ajax onreadystatechange...
    u call the background page which returns the output that u need after the database is updated....
    this is couse i ahve different background pages....
    one for database update and one for display output...

    but u can do it in one page too with php or whatever server script ur using
    cheers

  3. #3
    SitePoint Member
    Join Date
    Oct 2004
    Location
    DK
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    okay?

    I didn't understand your answer...

    Could someone please tell how the following is done.

    After updating database in the background, how can i display the new record on the page without reloading the page?

    Im really new to this but im able to do the update in the background, but not the new update page without refresh...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •