472,799 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,799 software developers and data experts.

how to return value from ajax function?

i want to return value from ajax function to the function where ajax call has been made.
Expand|Select|Wrap|Line Numbers
  1. function val()
  2. {
  3. var temp=ajaxfun();//ajax function;
  4. }
  6. function ajaxfun()
  7. {
  8. //url,type, data will go here and then
  9. success: function(somedata){
  10. //here i want to return data i.e. somedata
  11. //something like "return somedata" to val();
  12. }
  13. }
Mar 29 '13 #1
3 5203
8,658 Expert Mod 8TB
it doesn’t work like that with asynchronous AJAX calls.

you could of course use a synchronous call, but the you wouldn’t need a success callback function either.
Mar 29 '13 #2
77 64KB
Try This code

Expand|Select|Wrap|Line Numbers
  1. function cityconfirm()
  2. {
  3. var cityid=document.getElementById('city').value;
  4. alert(getcityvalue(cityid));
  5. return confirm('Are you sure you want to delete')
  6. }
  8. function getcityvalue(cityid)
  10. {
  12. jQuery.ajax({
  13. url: 'http://mysite.com/lookupcity.asp?cityid=' + cityid,
  14. type: 'get',
  15. dataType: 'text/html',
  16. success:function(data)
  17. {
  18. return(data);
  19. }
  20. });
  21. }
Feb 22 '21 #3
priti kumari
3 2Bits
function follow() {
get Products(function(d) {[url=["http://pritikumari.000webhostapp.com/priti[/URL]
//processing the data
function get Products(callback) {
var data;
u r l: 'u r l',
data: 'all product data to send',
success: function (resp) {
data = resp;
error: function () {}
}); // ajax asyn chronus request
//the following line wouldn't work, since the function returns immediately
//return data; // return data from the ajax request
Jul 14 '21 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Michael Satterwhite | last post by:
I wanted to centralize connection to a MySQL database, so I created a function that reads (eliminating extraneous) function connectDB() { $db = mysql_connect(-------);...
by: Bob | last post by:
Hi, I have a std::vector, say myVec, of some user defined object, say myOb. In my code, I have a function that searches myVec for a particular myOb. The way I was doing this was searching...
by: gsyoon | last post by:
hi, all. I'm trying to make a "framework" to store the return value of a function to a global memory. My first attempt was 1) void store_to_global( char * type_name ) { if ( strcmp(...
by: Seong-Kook Shin | last post by:
Hi. Just curiocity, Because of pre-ANSI C, it is possible to have a function without specifying return type of a function (which makes the return type 'int', though) and give no 'return'...
by: b_naick | last post by:
I have a class file in my ASP .NET C# application - defined as follows: namespace ABC { public class BizObj { public Style GetVal(int id) { Style temp = new Style(); // run some db queries...
by: igor.lautar | last post by:
Hi, How can I get the address of return value in function? ex. int function(int argument) { int *arg_address; int *rtn_address;
by: shapper | last post by:
Hello, I have a function inside a compiled class which code is as follows: Public Function Send() As Boolean ' Try
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
by: Shalini Bhalla | last post by:
i have 2 tables bank master and branch details having bankcode as a common feild . i have designed a form in which i am filtering branches according to a particular bank code using ajax ,...
Dheeraj Joshi
by: Dheeraj Joshi | last post by:
Hi... I have a php script which has a function call and function returns a value. But when i open it in browser and refresh the page the return value will get added to the old value. Code...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: Mushico | last post by:
How to calculate date of retirement from date of birth
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.