views:

1112

answers:

5

How to do an update status like what are you doing now (facebook + ajax) with Jquery?

I found a tutorial that very similar to this, but they using mootools, is there a tutorial that use Jquery?

I am a new to javascript and jquery, I need your guys help and advice

EDIT:

The mootool example can be found from here:

http://nettuts.com/tutorials/php/twitter-emulation-using-mootools-12-and-php/

+1  A: 

here is a nice example to do some simple jquery-ajax with PHP

Natrium
I found that already.. Not very helpful to my question though. DO you have others related to my question tutorials?
and why is this not helpfull to your question? Seems a perfectly clear example to me.The only difference is that you're not updating a status, but the order of the items.
Natrium
+2  A: 

Basically what you want to do is to make a jQuery POST request to the server with the contents of your form. (Take a closer look at the examples to understand how it works...) Store the posted data in your database, send a response to the client and use a callback function to update the page by re-loading the specific fields that should be updated.

I haven't seen any tutorials to create this specific functionality, but if you play around a little with jQuery and your server-side language-of-choice you should be able to figure it out pretty quickly.

Tomas Lycken
+1  A: 

you probably want to do this..

$("div").html("<span class='red'>Hello <b>Again</b></span>");

or

$("p").text("<b>Some</b> new text.");

Checkout JQuery Docs

Cherian
+1  A: 

@Tomas and @Natrium have basically told you what you need to know.

Since you say you are new to javascript and jQuery, I'd recommend you to check out http://docs.jquery.com/Main_Page

For Ajax specific documentation, check out http://docs.jquery.com/Ajax

To learn the basics of jQuery (even if you don't know a lot of javascript), I recommend the book "Learning jQuery" http://www.packtpub.com/learning-jquery-1.3/book/mid/220409c024ep

Here Be Wolves
What's with the @Name stuff? All answers have permalinks.
bzlm
hmm.. habits from twitter :) Anyway, linking to answers on the same question is too much work for a lazybones like me.
Here Be Wolves
A: 

If you were to follow the mootools example exactly as they have it, the javascript code would simply need to be changed to this to work (basically the same way) in jQuery:

$(function() {
    //make the ajax call to the database to save the update
    $.ajax({
        url: '<?php echo $_SERVER['PHP_SELF']; ?>',
        method: 'POST',
        beforeSend: function() {
            $('submit').attr('disabled','disabled');
        },
        complete: function(xhr,status) {
            $('submit').disabled = 0;
            $('#message').removeClass('success').removeClass('failure');
            $('#message').fadeIn(3000);
        },
        success: function(data,status) {
            //update message
            $('#message').text('Status updated!').addClass('success').fadeIn('medium');

            //store value, clear out box
            var status = $('#status').val();
            $('#status').val('');

            //add new status to the statuses container
            var element = $('<div class="status-box">');
            element.html(status + '<br /><span class="time">A moment ago</span>');
            $('#statuses').prepend(element);

            //place the cursor in the text area
            $('#status').focus();

        },
        error: function(xhr, status, error) {
            //update message
            $('#message').text('Status could not be updated.  Try again.').addClass('failure').fadeIn('medium');
        }
    });
});
KyleFarris
This is the coolest answer I ever received. Thank you very very much, i will test it see if its work
its not working.. but never mind, thanks for your effort anyway
I might have a typo in there somewhere. If you read through what I gave you, you might be able to see it. Just make sure you have FireBug turned on in Firefox when you use the code above and it will likely tell you what is wrong with it. Looks like I am missing a quote in there somewhere (I've fixed that now.). The code is sound, though... it should work as expected if you you follow the tutorial for the PHP/MySQL stuff.
KyleFarris