lundi 30 mai 2016

Razor MVC 3 Ajax returns 404

I'm trying to do a basic autocomplete via jquery AJAX, using Razor MVC 3 and Visual Studio 2012 (all of which I had never used before) My code is as follows


$(document).ready(function () {        
    $("#city").keyup(function () {
        var input = $(this).val();

function getCities(input) {
    var serviceURL = $("#autocompleteURL").val();    
    var url =
            type: "POST",
            url: serviceURL,
            data: {
                'guess': input
            success: function (data) {

Since i learned that it's not possible to use Razor syntax in a JS file, I'm getting the value from the view via a hidden input, like:

<input type="hidden" id="autocompleteURL" value="@Url.Action("AutoCompleteCity", "Controllers/SearchController")" />


 public class SearchController: Controller
       public ActionResult AutoCompleteCity(string guess)
            //database stuff here

I don't know if I'm missing something else. Any help will be greatly appreciated. Thanks!

Aucun commentaire:

Enregistrer un commentaire