Solved

Return value from jQuery Ajax call

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

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

Suggested Solutions

Title # Comments Views Activity
Where is this content coming from? 4 40
XJS:  how to throw error if no match found 8 57
Php variable to be sent back 3 34
PHP, Curl and XML 14 11
This article discusses four methods for overlaying images in a container on a web page
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

734 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