Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery and AJAX not working after deployed to server

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>
like image 848
Danger_Fox Avatar asked Apr 16 '13 19:04

Danger_Fox


1 Answers

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

like image 178
Amol Shiledar Avatar answered Sep 27 '22 21:09

Amol Shiledar