How to get container danymicly in Jquery.post.callback
I have some form containers with a form in each,
form.submit function like this:
$('.form-container form').submit(function(){
$.post(url,data,callback);
});
callback function:
function callback(data){
container.html(data);
}
Question is, how can I get the container, are there any way that I can pass it from submit 开发者_StackOverflow社区function?
Because the container is danymic, I cann't simply get it by id or so.
Thanks!!
I don't know what a "container" is in this sense, but if it's available in your submit function, then you can declare it in the submit function's local scope, and use it in the callback, either like so:
$('.form-container form').submit(function() {
var container = ...; // your container
$.post(url, data, function(data) {
container.html(data);
});
});
or if you prefer to keep the callback separate:
$('.form-container form').submit(function() {
var container = ...;
$.post(url, data, function(data) { callback(container, data); });
});
function callback(container, data) {
container.html(data);
};
精彩评论