Reputation: 9
On a page I have a form with some buttons. Each of these will call a specific controller method and display the related view. In addition, I have a button "X" which when clicked will extract specific info from the form data input. Then, I want to process these data on the server. This means I have to use Ajax. However, after the Ajax call succeeds, I want to display a new view file and at the same time send some data (an array) to this view.
I cannot use 'window.location' in the 'success' function of the ajax call to redirect to a URL because I cannot make use of the returned data any more.
How can I accomplish my task?
Update1
I will show snippets of code to explain more:
In projects\running.ctp
:
1) I have a form with checkboxes (id contains unique project id which I will collect from checked checkboxes)
2) When the button is clicked, I need to send these id's for processing on the server:
$.ajax({
type: 'POST',
dataType: 'JSON',
url: '/projects/groupCuttingList',
data: {'pj_ids': requiredPjIds},
/*success: function (data, textStatus, qXHR) {
//window.location='';
}*/
});
After the server processing is done, I want to display the returned data on a new view file. How to do it? (If I use window.location to redirect, I won't be able to send the returned data, which is a JSON array of arrays).
Upvotes: 0
Views: 346
Reputation: 923
What you could do is have your ajax function return rendered HTML, then in the success function replace the contents of a content wrapper with what was just returned.
You can use an empty layout to ensure there isn't anything other than the rendered HTML being returned, other than that it should be pretty straightforward.
Upvotes: 1