Hey there! Could someone please explain how I can use the AJAX load method to load a div
whose ID is stored in a JavaScript variable? In other words, the div that needs to be loaded has its ID saved as a JavaScript variable.
I'm facing an issue where I can't add quotes around the JavaScript variable containing the div's ID. The load method doesn't work unless I include quotes around the div ID.
function submitFormByAjax(obj){
// The ID of the div to be loaded is stored here.
// I don't know the value - it could be anything
var divid = $(obj).attr("id");
$.ajax({ type: 'post',
url: 'home_formhandler1.php',
data: currentform.serialize(),
success: function() {
$("#" + divid).load("home.php #" + divid);
}
});
}
This code isn't functioning correctly. It seems like JavaScript is treating the variable divid
as a string.