Solved

Ajax toggle status

Posted on 2014-01-24
4
375 Views
Last Modified: 2014-06-01
I've a page bookmark system in my site using the old coding style. Means that a user clicks on the bookmark button and the database updates with a page refresh. When the user is redirecting back instead of bookmark he is seeing the remove bookmark link. So far so good. At least works.

Now I want to have this feature using Ajax (no page refresh). When the user clicks the Bookmark link an Ajax request to be send to database and the link to change to "Remove bookmark". Clicking it new database update, new bookmark link update and so on.

How I can do it?
0
Comment
Question by:NickTERiS
4 Comments
 
LVL 44

Assisted Solution

by:Rainer Jeschor
Rainer Jeschor earned 250 total points
ID: 39806201
Hi,

just some sort of pseudo code.
You would want to use the jQuery.post() function, passing the data form values.
In the success callback you will have to verify the response if the database update was successful and if yes run additional jQuery functions to change the link text / button ...

Please have a basic look on the documentation page - especially the last sample:
http://api.jquery.com/jquery.post/

HTH
Rainer
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 39806241
Here is an EE article that shows all of the essential moving parts of jQuery / AJAX.  Please read it over and post back if you still have any questions.
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/A_10712-The-Hello-World-Exercise-with-jQuery-and-PHP.html
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Fulfillment API php code sample 1 38
Attach to file (img) a unique id 8 24
how to use Initialization Vector for openssl_encrypt() 5 21
Jquery 2 9
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question