简体   繁体   中英

using JavaScript variable in place of jquery selector

instead of $('#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"); 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.

var res;
$('#res').load( "mysql.php", function( response, status, xhr ) {
    res = response;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM