Solved

Return value from jQuery Ajax call

Posted on 2012-03-15
1
345 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
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

773 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