我的html是这样的
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link href="../../Content/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../Scripts/elastic.js"></script>
</head>
<body>
<input type="text" id="getText" placeholder="Enter text to search" onkeypress="setFocus(1)"
onblur="setFocus(0)" />
<input type="button" id="get" class="btn btn-success" value="Submit" />
<div id="smain">
</div>
<div id="smain1">
</div>
</div>
</body>
</html>
我的javascript看起来像这样
function getSuggest() {
var select = $("#select").val();
var search = $('#getText');
var text = search.val();
$.post('/Home/Index', { "value": text, "svalue": select }, function (data) {
$(data).each(function (index) {
results += data[index];
results += '<br/>';
});
$("#getText").autocomplete({
source:results
});
results = '';
if (focus == 1) setTimeout(function () { getSuggest() }, 300);
});
}
我正在使用jquery.ui API来实现自动完成功能 当我执行此操作时,我收到400个错误请求。我是新来的,请用这个
我的错误看起来像这样
GET http://localhost:29908/Home/Lightwater%20Valley%3Cbr/%3EKitSound%20X-
Dock2%…20Connector%20Clock%20Radio%20Dock%20for%20iPhone
/iPod%3Cbr/%3E?term=light 400 (Bad Request)
答案 0 :(得分:0)
我找到了解决方案并且工作正常。感谢您的建议@Rory McCrossan
$(document).ready(function () {
$("#getText").autocomplete({
source: function (request, response) {
var select = $("#select").val();
var search = $('#getText');
var text = search.val();
$("#smain").empty();
$.ajax({
url: "/Home/Index",
type: "POST",
dataType: "json",
data: { "value": text, "svalue": select },
success: function (data) {
response($.map(data, function (item) {
return { value: item };
}))
}
})
}
});
})