TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
أماني مفيد
NA
142
17.4k
Autocomplete Text box Ajax
Sep 6 2020 2:12 AM
i have bellow script fro autocomplete tex box , the fucntion in controller take parameter (prifix )
the script return all data how i can pass the prifix from ajax to controller for example when i type (a) it retuen all data start or not statrt with (a)
this is the script
<head>
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<input id='CountryName'/>
<span id='CountryID'></span>
<script>
//var data2 = ["Ahmad Hoshya", "Amani Mustafa", "Maamoun Zakarneh", "Sabeel"];
var data2;
//var firstname = $('#CountryName').val();
var firstname = document.getElementById("CountryName").value;
$.ajax({
url: '/Home/GetRecord?prefix='+ firstname,
dataType: "json",
type : "post" ,
data: data2,
success: function (data) {
data2 = data;
},
error: function (xhr, status, error) {
alert("Error");
}
});
$('#CountryName').autocomplete({
data: { search: $("#searchInput").val() },
source: function y(request, response) {
response($.map(data2, function (item) {
return {
label: item.t,
value: item.t
}
}));
}
,
select: function (e, ui) {
e.preventDefault();
$(this).val(ui.item.label);
$('#CountryID').html(ui.item.value);
}
});
</script>
</body>
Reply
Answers (
2
)
MVC Related bug
Dropdownlistfor On your View return null, how to fix it?