MVC 5 invalid JSON primitive

Bin ich zu schreiben versucht, eine auto-complete mit ajax in MVC5, aber egal was ich versuche ich bekomme die Fehlermeldung invalid JSON primitive.
Wenn ich die url manuell localhost:5088/GetData?inpt=[Abfrage] ich bin in der Lage, um zu sehen, die json zurückgeben.

Was ich verstehen online , ich gebe die "Daten:" - parameter falsch. Ich versucht, indem Sie in"", aber es hat nicht funktioniert.

Mein Controller :

  public  JsonResult GetData(string inpt)
        {
            try
            {
                var node = //some values here , cause its too long I deleted it 
                foreach (var node in q)
                {
                    string scity = node.Attribute("CityName").Value.ToUpper(new CultureInfo("tr-TR", false));
                    string ccity = node.Attribute("CityCode").Value;
                    string ccode = node.Attribute("CountryCode").Value;
                    if (ccity != oldcity)
                    {
                        result.Add(new HavaAlani { SehirAdi = scity, HavaAlaniKodu = ccity, HavaAlaniAdi = scity + ", " + ccode, Sehirmi = true });
                        oldcity = ccity;
                    }
                    result.Add(new HavaAlani { SehirAdi = scity, HavaAlaniKodu = node.Attribute("Code").Value, HavaAlaniAdi = node.Value, Sehirmi = false });
                }
            }
            catch
            {

            }

            return Json(result, JsonRequestBehavior.AllowGet);
        }
    }

Meine JS :

    $('input.suggestBox').each(function () {
    //$(this).jsonSuggest(air.Lines);
    $(this).autocomplete({
        source: function (request, response) {
            $.ajax({
                url: "dataAl/GetData",
                data: { inpt: request.term },
                dataType: "json",
                type: "POST",
                contentType: "application/json; charset=utf-8",
                dataFilter: function (data) { return data; },
                success: function (data) {
                    response($.map(data.d, function (item) {
                        return {
                            code: item.HavaAlaniKodu,
                            value: item.HavaAlaniAdi,
                            iscity: item.Sehirmi
                        }
                    }))
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.responseText);
                }
            });
        },
        minLength: 2
    }).data("ui-autocomplete")._renderItem = function (ul, item) {
        var cls = "airport";
        if (item.iscity)
            cls = "city";
        return $("<li></li>")
                .data("item.autocomplete", item)
                .append("<span class='span-" + cls + "'></span>")
                .append("<a class='ui-autocomplete-" + cls + "'>" + item.value + " (" + item.code + ")" + "</a>")
                .appendTo(ul);
    };

});
Können Sie ein Beispiel für die JSON Zurückgegeben?
Es tut JSOn zurückgeben , es gibt die Warnung "invalid JSOn primitive:inpt." Aber es gibt die Fehler im html-format innerhalb der Titel-tag von Kopf
hmm... Das ist komisch, ich allerdings, dass insbesondere der Fehler entstand mit jquery, nicht MVC. Wenn Sie einen Haltepunkt in die Aktion scheint es zu vervollständigen? Wenn nicht, kann Sie auch zeigen, wo das Ergebnis verkündet wurde. Auch versuchen Sie, DataType "json-text" oder "text/json"
Hinzugefügt zu beantworten - ich glaube, Sie brauchen, um stringify Ihre Daten-Objekt als gut.

InformationsquelleAutor Burak Gazi | 2014-03-12

Schreibe einen Kommentar