Solved

Ajax call to server using jquery

Posted on 2009-07-01
1
378 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
ID: 24759426
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to dynamically set the form action using jQuery.
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…

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