简体   繁体   English

MVC2 Ajax问题!

[英]MVC2 Ajax Question!

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. 那么..我想知道是否使用jquery发送'get'ajax请求的方法,将模型打包到url中并发送包含模型的重定向的javascript是一个很好的做法,我开始打墙,想知道我是不是从根本上做错了。

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. 所以我有一个网格,在一行点击我发送ajax请求以获取用户的模型基于一个键,从那里我把模型放入一个由回调执行的重定向,这工作FINE除了我得到粗略的网址,让我陷入混乱,我应该避免。

any light shown will be appreciated, even if its a, wtf were you thinking comment :D 任何显示的光都将不胜感激,即使您认为a,wtf是评论:D

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. 通常在GET请求中发送大量参数并不是一个好习惯,因为它会导致长网址,并且您可能会达到网址长度的限制,这可能因浏览器而异。

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. 在这种情况下,您应该更喜欢将这些参数作为POST请求发送到控制器操作,该操作将持久化/更新数据存储中的模型,并重定向到另一个控制器操作,仅传递数据存储中该模型的唯一标识符。 The action you are redirecting to would use the id passed in the url to fetch the model back from the datastore. 您将重定向到的操作将使用url中传递的ID从数据存储中取回模型。

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. 获取模型,然后在回调中重新定向到页面,而不是单击行,为什么不单击该行,只需发送将您带到重定向页面的ID。 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. 然后,此页面可以使用querystring参数异步执行get请求,然后加载从操作返回的json(或其他值)。

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. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM