Solved

Ajax call to server using jquery

Posted on 2009-07-01
1
376 Views
Last Modified: 2012-05-07
Hello.  Am new to jquery and ajax.  I need to make an ajax call that will add or remove a user's favorite location on click.  The two values are passed in json: result and locationcode.  This is what I have so far, not sure how to construct the rest:


$('.add-remove-button').bind('click',function(){

		$.post(

			

		);

});

Open in new window

0
Comment
Question by:aznprncritic
1 Comment
 
LVL 16

Accepted Solution

by:
anoyes earned 500 total points
Comment Utility
The docs for the $.post function are here: http://docs.jquery.com/Ajax/jQuery.post

But basically, your script will look something like this:

$('.add-remove-button').bind('click',function(){
  $.post('/path/to/script.php', data, function(resp) {
    alert(resp);
  });
});

data is just a variable here that contains the data you want to post to the script, and function(resp) is the callback function that is triggered when the request completes.  The body of the response is passed into the function as the first parameter, in this case I've used resp as the variable name.  Ideally you'd return the status of the save and alert the user if something went wrong.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now