开发者

Render nothing !

I have a partial that show a form into a page. As I submit the form, I just want that the controller do its operation and come back to the page without render anything. I 开发者_运维问答just want to show the flash message of success or error and nothing more. But the controller by default try to render a new page. How can I do to avoid this behavior ?


To do what you want, only using asynchronous HTTP request with JavaScript (AJAX). So you post the values of the form's fields and update the flash area with the result. You can use jQuery to help in ajax requests:

<Edited>

If you do not have a flash area in your page you can create it putting a div element at the top or your page (or any other place you want). Then in the button's onclick event you put this:

<input type=button onclick="$.post('/controller/action/update', $('#testform').serialize(), function success(data, textStatus, jqXHR){$.('#flash').html(data)})">

This function sends the form's data to the server and when return the callback function is called (success). Then you need only to update the flash content with the returned data.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜