?
Solved

Ajax call to server using jquery

Posted on 2009-07-01
1
Medium Priority
?
383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 16

Accepted Solution

by:
anoyes earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses

771 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