IsaacBen's avatar

Ajax comments

At the moment I can upload images in my website, and also I can add comments through popup in the same page, the problem is I don't want it to refresh the page so of course I will need to use Ajax. Can someone suggest where to go and look? How can I use Ajax to show results from the database? Am I supposed to add the comments to a json file so I can fetch them through that?

0 likes
1 reply
BENderIsGr8te's avatar

Sounds like you are new to AJAX. All AJAX really is, is a scary sounding acronym that means "visit a page in the background and give me the results in javascript so I can then do things with them".

I would start with JQuery (http://jquery.com). It's the most popular Javascript Library and it does a great job at Ajax requests across different browsers (with IE being the only browser you really have to worry about differences on...go figure).

AJAX requires you to be somewhat prevalent in JavaScript. If your JavaScript isn't very strong you had better spend some time learning about it. Here is a great tutorial from Envato on Youtube https://www.youtube.com/watch?v=hARp2xoTNHg

Essentially your flow will be like this....

...some action occurs...(submitting a form for example)

...you do a request (POST if putting data, or GET if simply retreiving data) to a page you have built. That page is designed to return JSON instead of HTML.

...You then take the JSON data (which can itself contain strings of HTML or other data) and then you then add it to your current document (using JQuery methods for appending to the end of something or putting it in the middle of something).

That video tutorial has a special section on AJAX about 9 or 10 videos in, so check it out.

Please or to participate in this conversation.