[英]using JavaScript variable in place of jquery selector
instead of $('#hello').load("mysql.php");
而不是
$('#hello').load("mysql.php");
,where the selector is a html element , is there any way i can use .load() to store the result in a javascript variable something like var res; $('#res').load("mysql.php");
,其中选择器是一个 html 元素,有什么方法可以使用 .load() 将结果存储在一个类似于
var res; $('#res').load("mysql.php");
的 javascript 变量中var res; $('#res').load("mysql.php");
var res; $('#res').load("mysql.php");
You can make use of the callback, and store the response to a variable.您可以使用回调,并将响应存储到变量中。 However you do have the asynchronous nature of this function to bare in mind, meaning the
res
variable will be undefined until you get the response.但是,您确实需要牢记此函数的异步性质,这意味着在您获得响应之前,
res
变量将是未定义的。
var res;
$('#res').load( "mysql.php", function( response, status, xhr ) {
res = response;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.