I have a project that works fine on my local machine, but after its been deployed to the server, fails to work. If I put breakpoints in the javascript it hits them and goes through the code, but doesn't do what it's supposed to (jquery autocomplete). I've even made sure the script files I need are stored on the server. Is there something I'm over looking?
Code that needs to be run:
<script type="text/javascript">
$(document).ready(function () {
$("input.autocomplete").autocomplete({
appendTo: '.container',
source: function (request, response) {
$.ajax({
url: '/Home/GetUsers',
type: "POST",
dataType: "json",
data: { query: request.term },
success: function (data) {
response($.map(data, function (item) {
return { label: item, value: item };
}));
}
});
}
});
})
</script>
_Layout.cshtml page where jquery is included:
@Styles.Render("~/Content/css")
@Styles.Render("~/Content/themes/base/jquery-ui.css")
@Styles.Render("~/Content/themes/base/jquery-ui.autocomplete.css")
@Scripts.Render("~/bundles/modernizr")
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery-ui-1.8.20.js")"></script>
i am also face this issue in my mvc project ....
i am solved this issue by following steps.
1) Put this in your Layout page in script section
<script type="text/javascript">
var RootUrl = '@Url.Content("~/")';
</script>
2) add the "RootUrl" variable in ajax url. (it's also working your Js File you add "RootUrl" before your ajax url)
url: RootUrl +'Home/GetUsers';
It's working prefect for me but anyone have other solution then plz post me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With