Solved

Return value from jQuery Ajax call

Posted on 2012-03-15
1
366 Views
Last Modified: 2012-03-24
Am trying to figure out how to return a value after making an ajax call.  In the example below, option 1 and option 2 both correctly return values, but I do not seem to be getting the same result with option 3.  Here's the code:
function getLevel(cat){
	if(cat==1){
		return $('#billed').val();
	}
	else if(cat==2){
		return <?php echo $prior; ?> 
	}
	else if(cat==3){
		var eventdate = $('#billed').val();		
                $.ajax({
                        url: sURL+"utility/eventDateAjax/"+eventdate,
                        type: "POST",                        
                        success: function(data){
                                alert(data);
                                return data;
                        }
                });
	}
}

Open in new window

Can someone tell me what I am doing wrong?  Thanks.
0
Comment
Question by:DanielAttard
[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 22

Accepted Solution

by:
Mrunal earned 500 total points
ID: 37727884
Hi,
What you are getting in alert(data)?

Check with alert(data.d);

Also try this:

$.ajax({
                        url: sURL+"utility/eventDateAjax/"+eventdate,
                        type: "POST",                        
                        success: function(data){
                                alert(data);
                                ProcessData(data);
                        }
                });

Open in new window


And in function ProcessData() process your response.

function ProcessData(output)
{
 //process your response here
}

Open in new window


OR

take look at jQuery Ajax manual for-

 var htmlOutput = $.ajax({
  url: "pagename.php",
  async: false
 }).responseText;
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

628 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