[英]I need to populate a form when I click on a dropdown. Which option is more performant?
I can either: 我可以:
-Get the information using AJAX, creating a request every time I click on the dropdown. -使用AJAX获取信息,每次我单击下拉列表时都会创建一个请求。
-Populate the form passing the information to div like this: -像这样填充将信息传递给div的表格:
@foreach($items as $item)
<div id="name_{{$item->id}}" value="{{$item->name}}"></div>
<div id="date_{{$item->id}}" value="{{$item->date}}"></div>
...
@endforeach
And then setting the value of the form with javascript, making a single request that extracts all the information and passing it to the site. 然后使用javascript设置表单的值,发出一个提取所有信息并将其传递到网站的请求。
I have already done both, but I would like to know which one would be the most performant. 我都做过,但是我想知道哪一个是性能最好的。
The answer is both, but depends on the case. 答案是两种,但要视情况而定。
For instance if you use the ajax method and the dropdown box is never pressed is better than the passing the values. 例如,如果您使用ajax方法,并且从不单击下拉框比传递值更好。
If the dropdown box is hit once or more than once, the second method will be better. 如果下拉框被单击一次或多次,则第二种方法会更好。 But you will have also a downside: you'll not get the newest version of the dropdown box information from where ever you get it.
但是您也有一个缺点:无论您从哪里获得下拉框信息的最新版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.