1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Create status update using php & ajax

Discussion in 'PHP' started by miexl, Sep 26, 2009.

  1. #1
    Hi,

    I would like to ask or request to anybody to create a simple script using ajax to update a status without reloading the page. To give you an idea it's just like facebook's status update. If anyone here would like to share their knowledge then thanks in advance. :D
     
    miexl, Sep 26, 2009 IP
  2. dweebsonduty

    dweebsonduty Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    Digital Goods:
    1
    #2
    Use Jquery for this, it is alot easier.

    Assumptions:
    1.You have a textarea or field with id="updater"
    2. You have a button or link with onclick="updatestatus()"


    What the code does:
    1. Jquery code Posts the value of updater to a php page
    2. PHP page gets the update and does something then echos 1
    3. Jquery code sees the 1 and the declares a success

    Javascript
    
    <head>
    <script type="text/JavaScript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
     <script type="text/JavaScript">
    function updatestatus()
    {
    var updatetext = $("#updater").val();
    
    $.post("updatestatus.php", {
    	message: updatetext
    	},
    	function(data)
    		{
    		if (data == 1)
    			{
    			$("#updater").val("");
    			$("#updatesuccess").fadeIn("slow").append("<div id=\"noerror\">Your Update Has Been Submitted</div>");
    			
    			}
    		});
    }
    </script>
    </head>
    
    Code (markup):
    PHP
    
    $msg = $_POST["message"];
    
    if ($msg)
    {
    // Do something
    echo 1;
    }
    
    PHP:
     
    dweebsonduty, Sep 26, 2009 IP