Solved

Ajax call to server using jquery

Posted on 2009-07-01
1
382 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 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

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 …
This article discusses how to implement server side field validation and display customized error messages to the client.
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)

690 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