1

我正在使用 Datajs 调用 Web API,它在每个浏览器中都可以使用,但是当我通过 Phonegap 调用它时,我收到错误 Http Request failed 。

     function DefaultHandler() {
        var oldDefaultHandler = OData.defaultHandler;
        OData.defaultHandler = {
            accept: oldDefaultHandler.accept,
            read: function (response, context) {
                var contentType = response.headers["Content-Type"];
                if (contentType && contentType.indexOf("text/html") === 0) {
                    response.data = response.body;
                } else {
                    oldDefaultHandler.read(response, context);
                }
            },
            write: function (request, context) {
                oldDefaultHandler.write(request, context);
            }
        };
    }
    function GetContact() {
        $('#products').html('');
        OData.defaultHttpClient.enableJsonpCallback = true;
        DefaultHandler();
        OData.read(
                     {
                         requestUri: "http://192.168.11.46/odata/Contact",
                         enableJsonpCallback: false,
                         datatype: "json",
                         headers: {     'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET', 'Content-Type': 'application/json', 'Accept': 'text/html', "Authorization-Token": "94,214,182,1,98,51,181,18,190,167,152,19,225,97,211,221,145,78,188,26,247,172,226,13,90,113,105,2,226,15,137,12,190,22,95,226,215,9,111,95,162,33,36,220,238,197,99,169,158,140,170,61,3,186,190,97,244,173,125,212,3,135,172,111,235,229,133,101,234,188,104,188,127,10,188,221,72,120,48,25,184,56,215,80,87,83,117,30,57,241,133,80,137,220,185,220,230,0,20,122,181,0,106,69,234,27,106,212,187,77,77,27,39,159,31,253,140,105,43,167,210,238,35,71,44,251,180,199" },
                         method: "GET"
                     },
                     success,
                        error
                    );
    }
   success = function (data) {
                   alert('success Odata');
               };
    error = function (err) {
                   alert('error Odata');
               };

我需要在 Eclipse 或模拟器中设置什么设置吗?

4

0 回答 0