dimanche 28 juin 2015

JSONP issue with Cordova and WebAPI Error: Unexpected token :

I'm having an issue with a some cross site communication in a cordova app I'm toying with, the error is on the ajax call below.

Error in browser

Uncaught SyntaxError: Unexpected token :

The interesting part is that in the response the JSON is there, it just don't arrive to the success.

The WebAPI method

public JsonResult Search(string query)
{
    query = query.ToLower();
    RPAS_Operator op = new RPAS_Operator();
    SearchResultModel sm = SearchSupport.ParseData(op.RPAS_Operators.Where(a =>
    a.Name.ToLower().Contains(query)));
    return Json(sm, JsonRequestBehavior.AllowGet);
}

The jQuery

function Search(query) {
    var url = baseURI + "Search/Search/?query=" + query;
    $.ajax({
        url: url,
        type: 'GET',
        dataType: 'jsonp',
        cache: false,
        jsonp: 'callback',
        success: function (data) {
            console.log(data);
            document.getElementById("testOutput").innerText = data;
        }
    });
}

Aucun commentaire:

Enregistrer un commentaire