0

So.. I am wondering if the method of sending a 'get' ajax request with jquery, packaging a model into a url and sending the javascript a redirect including the model is a good practice, Im starting to hit some walls and wondering if Im fundamentally doing this incorrectly.

So I have a grid, on a row click I send an ajax request to get the model of the user based on a key, from there I put the model into a redirect that gets executed by the call back, this works FINE except I get gross URLs and feel im getting my self into a mess I should be avoiding.

any light shown will be appreciated, even if its a, wtf were you thinking comment :D

2 Answers 2

1

Instead of clicking the row, getting the model and then re-directing to the page in the call back, why don't you click the row, just sending the id which takes you to the re-directed page. Then this page can use the querystring parameter to do the get request async and then load in the json returned (or whatever) from the action.

This way, the urls will be clean and simple and book markable, but also reduce having to send more data than is required in round trips.

Hope this helps.

1

Generally sending lots of parameters in a GET request is not a good practice as it leads to long urls and you may hit the limit of url length which could vary across different browsers.

In cases like this you should prefer sending those parameters as a POST request to the controller action which would persist/update the model in your datastore and would redirect to another controller action passing only the unique identifier of this model in the datastore. The action you are redirecting to would use the id passed in the url to fetch the model back from the datastore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.