Solved

Return value from jQuery Ajax call

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now