0

I am building a comment system. so, I have a php page that displays one comment. now I have a php Want to load all comments in a single page. how do I take the data from file A and display it in file B?

Furthermore and more importantly, I have a upvote button, when you press it some script needs to get executed, I can write that script, but than how can I make it happen?

I really don't know ajax but somehow I have a feeling it has something to do with this... how do i do this?

I can only think of two methods for first one, and nothing for second one. I thought of including the HTML using php "include" or use Iframes, both solutions seem weird...

I Have programmed in php for a while now, but this is the first thing I actually do with it...

Thanks in advance, Fingerman.

10
  • 8
    I really don't know ajax what about reading one of zillions tutorials over the net? Commented Apr 11, 2011 at 10:37
  • I will if you say it has something to do with it... but currently I'm clueless. If it doesn't, I will when I have time. If it does, I'll need to do it now. Commented Apr 11, 2011 at 10:41
  • SO is not here to teach you stuff from scratch. Go away, read the billion ajax tutorials on the web, try stuff for yourself. Figure out what you can and can't do, and apply your new knowledge to the issue at hand. Commented Apr 11, 2011 at 10:41
  • 2
    Visit this link [api.jquery.com/category/ajax/] to know how to process ajax using jquery. This will help you very much. Commented Apr 11, 2011 at 10:44
  • 1
    for the upvote feature it's AJAX indeed. for the comments your question is extremely unclear. You don't have any data in a file A, but code only. a data is stored in database I am assuming. you may either include the code from file B or write another code to show comments. I see no point in code showing only one comment though Commented Apr 11, 2011 at 10:45

2 Answers 2

3

First of all to create a upvote button do something like:

<img src=".." id='upvoteButton' />

And Use JQuery with AJAX like:

$("#upvoteButton").live('click', function(){
        postData="data="+value; /* Data that you may want to pass to your script */
        $.ajax({
            type: "GET",
            url: "yourSecript.php",
            async: true, /* If set to non-async, browser shows page as "Loading.."*/
            cache: false,
            data: postData,
            success: function(data){ 
            }
        });
        return false;
    });

Please let me know if you are not clear....

Sign up to request clarification or add additional context in comments.

1 Comment

THANK you! you saved me quite some time... I should learn ajax myself thogh...and Jquery... I have a lot to learn :D
2

Yes, you need AJAX for that if you do not want to reload the page.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.