473,412 Members | 2,994 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 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. }
  5.  
  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. }
  14.  
Mar 29 '13 #1
3 5246
Dormilich
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
Sherin
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. }
  7.  
  8. function getcityvalue(cityid)
  9.  
  10. {
  11.  
  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
console.log(d);
});
}
function get Products(callback) {
var data;
$.ajax({
u r l: 'u r l',
data: 'all product data to send',
success: function (resp) {
data = resp;
callback(data)
},
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

0
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(-------);...
5
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...
4
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(...
1
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'...
3
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...
11
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;
4
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
2
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...
17
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 ,...
19
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.