jQuery autocomplete - 缓慢服务器vs本地
问题描述:
根据标题我只面临一次部署的性能问题。它是一个ASP.NET MVC5站点,并部署在Azure上。我们正在讲话vs几秒钟:/jQuery autocomplete - 缓慢服务器vs本地
我可以准备一个视频或任何有助于解决此问题的内容。 没有JS错误黯然抛出:/
带电作业的图像,它最终显示7/8秒后如..如果不是很长。 代码传入...
$(document).ready(function() {
$("#SerialSearch").autocomplete({
autoFocus: true,
//delay: 0,
minLength: 2, // minimum length to trigger suggestions
select: function(e, ui) { // define select handler
//alert(ui.item.value);
//hitting enter key on selected item works, mouse clicking after 609 on V609xxx will submit 609 sadly
//With this I override the problem
$('#SerialSearch').val(ui.item.value);
//alert('here');
$(this).parents('form').submit();
},
source: function (request, response) {
@*var modelDataJSON = '@Html.Raw(Json.Encode(Model))';*@
var check = @Html.Raw(val);
//var modelDataJSON = JSON.stringify(check);
$.ajax({
url: "/Devices/DeviceSearch",
type: "POST",
dataType: "json",
data: { Prefix: request.term, model: check },
success: function (data) {
//alert('success');
response($.map(data, function (item) {
return { label: item.SerialNumber, value: item.SerialNumber };
}))
}
})
}
//messages: {
// noResults: "", results: ""
//}
});
})
CSHTML:
@{
ViewBag.Title = "Devices";
Layout = "~/Views/Shared/_Layout.cshtml";
//var val = Json.Encode(Model);
//Using viewdata to load in mem entire device list
var val = Json.Encode(@ViewData["FullDeviceList"]);
}
@using (Html.BeginForm(FormMethod.Get))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
<div class="form-group">
<div class="col-md-12">
@Html.EditorFor(model => model.SerialSearch, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>
</div>
}
答
做的是确定问题的根源的第一件事。 我假设你有一个服务器端的自动完成控制源,并通过Ajax调用获取数据。在本地(开发站点?),Ajax调用的延迟将是最小的。在Azure上,由于主机是远程的,我预计延迟会增加。 (当然,不知道你的实现,这只是猜测)
请给我们一个[最小,完整和可验证的例子](http://stackoverflow.com/help/mcve) – Liam
你的问题是什么? – JohnH
哇,你们快速:)来吧 – David