从ajax返回数据以在另一个ajax中使用(return data from ajax to be used in another ajax)
首先是ajax
function testAjax() { $.ajax({ url: "getvalue.php", success: function(data) { callback(data); //return data; } }); }
回调函数
function callback(data) { return data; }
另一个使用来自另一个ajax的回调数据的Ajax
$.ajax({ url: "getvalue.php", success: function(data) { //how to get the data from callback function to be used here //return data; } });
我有一个函数的ajax调用,并从该ajax请求获取数据我有一个回调函数。
我的问题是如何使用回调函数中的数据在我的第二个ajax请求中使用?
First ajax
function testAjax() { $.ajax({ url: "getvalue.php", success: function(data) { callback(data); //return data; } }); }
Callback function
function callback(data) { return data; }
Another Ajax that uses data from callback that is from another ajax
$.ajax({ url: "getvalue.php", success: function(data) { //how to get the data from callback function to be used here //return data; } });
I have an ajax call from a function and to get the data from that ajax request i have a callback function.
My question is how can I use the data from the callback function to be used in my second ajax request?
原文:https://stackoverflow.com/questions/44322021
最满意答案
删除您包含的代码块,并查看以下代码返回的内容。
var_dump(function_exists('send_res'));
如果你得到假,你将该文件包含两次该文件,替换:
include
withinclude_once
和replacerequire
withrequire_once
。另一种选择,将你的代码放在这个if语句中,如下所示:
if (!function_exists('sendRes')) { function sendRes($s_attachment) //this is line 3 { /*Snip : processing message details..*/ try { mail($to, $subject, $message, $headers); } catch (Exception $e) { logMessage("An error occured Sending fingerprint:" . $e->getMessage()); } } //this is line 54 }
remove the block of code you included and see what the code below returns.
var_dump(function_exists('send_res'));
If you get false, you're including the file with that function twice, replace:
include
withinclude_once
and replacerequire
withrequire_once
.Another alternative, put your code in this if statement like this:
if (!function_exists('sendRes')) { function sendRes($s_attachment) //this is line 3 { /*Snip : processing message details..*/ try { mail($to, $subject, $message, $headers); } catch (Exception $e) { logMessage("An error occured Sending fingerprint:" . $e->getMessage()); } } //this is line 54 }
相关问答
更多-
正如错误所述,您正在重新声明函数_createCustomer ,这会导致致命错误。 你有2个声明: /home/user/public_html/painel/modules/servers/resellerclubmdhostingin/resellerclubmdhostingin.php:483 /home/user/public_html/painel/modules/servers/resellerclubvpsus/resellerclubvpsus.php:486 您应检查文件并删除一个声 ...
-
您可能想使用匿名函数。 将代码切换到此: public static function ReplaceUrlToHtmlLink($source) { return preg_replace_callback('!(((f|ht){1}(tp://|tps)|(www.))[-a-zA-Z0-9@:%_+.~#?&//=]+)!i', function ($groups) { $url = $groups[1]; return ...
-
这是简单的解决方案: print_r(get_declared_classes()); Here's the simple solution: print_r(get_declared_classes());
-
致命错误:无法重新声明connectt()(之前声明为(Fatal error: Cannot redeclare connectt() (previously declared in)[2023-05-19]
请从foreach循环中删除connectt()函数。 这是你应该工作的最终代码很久以前。 从来没有时间回答我自己的问题。 这个问题是由studio包引起的,因为这两个包都是用studio命令创建的。 通过composer安装两个包之后没有问题。 Long time ago. Never had the time to answer my own question. the problem was caused by the studio package because both packages were made with the studio command. After ins ...发生这个问题是因为你试图多次定义函数httpGet (它在循环中)。 简单地将它移除到外面,将定义该功能,并允许稍后在脚本中使用它。 另请参阅此答案 。 //google site search start here function httpGet($url15) { $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url15); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); // ...删除您包含的代码块,并查看以下代码返回的内容。 var_dump(function_exists('send_res')); 如果你得到假,你将该文件包含两次该文件,替换: include with include_once和replace require with require_once 。 另一种选择,将你的代码放在这个if语句中,如下所示: if (!function_exists('sendRes')) { function sendRes($s_attachment) //this is ...问题是$obj是tags一个实例,而tags::index()没有$from参数。 所以当你调用$obj->index()时会发生什么: tags::index()调用parent::index() (这是questions::index() ),不带任何参数。 questions::index()接收任何参数,因此$from为NULL 由于$from不等于'test' ,因此它调用$this->test() 。 请记住,就PHP而言, $this指的是$obj ,所以是一个tags实例。 所以questi ...致命错误:无法重新声明user_defined_function()(Fatal error: Cannot redeclare user_defined_function() [duplicate])[2023-04-13]
这是因为PHP将../data/config.inc.php和data/config.inc.php视为不同的文件。 它不知道它已经包含它,因为文件路径不同。 你有几个选择; 您可以使用realpath()返回文件的整个路径; require_once(realpath('../data/config.inc.php')); 或者,您可以在$_SERVER使用DOCUMENT_ROOT属性。 require_once($_SERVER['DOCUMENT_ROOT'] . 'data/config.inc ...无法重新声明两个功能(Cannot redeclare two functions)[2022-03-26]
不要嵌套函数 - 每次调用外部函数时,当前代码都会声明内部函数,从而导致第二次出错: function ov3rfly_replace_include_blank($name, $text, &$html) { $matches = false; preg_match('/相关文章
更多- AJAX问题
- ajax数据安全的问题
- ajax验证用户注册
- AJAX JSON 乱码
- jquery ajax方法url请求action没有返回json数据。
- Ajax跨域调用的范例
- ajax怎么提交带文件上传表单
- ajax跨域问题的解决方案
- 最近遇到一个Ext.Ajax.request的奇怪问题
- 老问题,Strust2 + Ajax中文乱码
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)