开发者

Refreshing a single div element in a page with jQuery?

I'm asynchronously posting a form, and I want to 开发者_Go百科refresh a div element upon completion of the form post. I have everything coded already, I just don't know how to (and if it is even possible) to refresh a single div in this manner. Any help?


if the div has an id of "foo", and the name of your data is 'data'

$(#"foo").html(data);

this would be in the callback of your post or ajax call

$.post(myURL, function (data) {
   $(#"foo").html(data);

}


If you have the HTML, then it's as simple as:

$('#yourDiv').html(responseFromYourAjaxCall);

If you're asking how to get the response from your ajax call, it's like so:

$.ajax({
    url: 'my/url',
    type: 'POST',
    success: function(data)
    {
       // This Callback is executed when the post is successful.
       // 'data' is the response from the server. 
    }
});


You might be interested in my AJAXFetch jQuery plug-in, which lets you use markup to perform AJAX posts and refresh elements (like your div) on the page with the result.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜