JQuery: return values to load callback function
It's required to partial upload Html page with $(selector).load('/sitePath', params, function() { ... });
method. Html layout comes ok but it would be nice to return some additional values for jav开发者_JAVA百科ascript also.
Nowadays I return special javascript block with javascript variables inside html layout to read their values on load callback. What is the best practice to perform such operation?
Thank you in advance!
I'd go for JSON
and .ajax()
.
$.ajax({
url: '/sitePath',
dataType: 'json',
type: 'POST',
data: params,
success: function(data){
$(selector).html(data.newcontent);
var info = data.additionalinfo;
}
});
Of course assumes that you create a JSON
string on your server that helds both, a property named newcontent
which should contain html markup
and a property named additionalinfo
.
精彩评论