我正在创建一个cordova apache应用程序,在其中我与web服务器通信(获取并向http://192.168.1.1/cgi/json/***发送http请求)
要从服务器恢复响应,我添加了以下代码:

http.addEventListener("load", processRequest, false);

function processRequest()
{
        if(http.readyState == 4 && http.status == 200)
        {
           alert("processRequest");
           alert(http.responseText);
           var response = JSON.parse(http.responseText);

           alert("response1 =" + response);
           var obj=jQuery.parseJSON(response);
           alert("session1"+obj.id);
           var myParams =obj.parameters;
           session_ID = myParams.id;
           alert("session2"+ myParams.id);
      }


}

当我调试时,调试器没有进入processrequest()函数,我无法在发送第二个请求“post”时恢复会话id
我使用的环境:
乌班图
Cordova版本:6.1.1
nodejs版本:v0.10.25
火狐
在网络控制台中:
已阻止跨源请求:相同源策略不允许读取http://192.168.25.1/cgi/json-req?req=%7B%22request%22%3A%7B%22id%22%3A0%2C%22session-id%22%3A%220%22%2C%22priority%22%3Atrue%2C%22actions%22%3A%5B%7B%22id%22%3A0%2C%22method%22%3A%22logIn%22%2C%22parameters%22%3A%7B%22user%22%3A%22admin%22%2C%22persistent%22%3A%22true%22%2C%22session-options%22%3A%7B%22nss%22%3A%5B%7B%22name%22%3A%22gtw%22%2C%22uri%22%3A%22http%3A%2F%2Fsagemcom.com%2Fgateway-data%22%7D%5D%2C%22language%22%3A%22ident%22%2C%22context-flags%22%3A%7B%22get-content-name%22%3Atrue%2C%22local-time%22%3Atrue%2C%22no-default%22%3Afalse%7D%2C%22capability-depth%22%3A2%2C%22capability-flags%22%3A%7B%22name%22%3Atrue%2C%22default-value%22%3Atrue%2C%22restriction%22%3Atrue%2C%22description%22%3Afalse%2C%22flags%22%3Atrue%2C%22type%22%3Atrue%7D%2C%22time-format%22%3A%22ISO_8601%22%2C%22depth%22%3A2%2C%22write-only-string%22%3A%22_XMO_WRITE_ONLY_%22%2C%22undefined-write-only-string%22%3A%22_XMO_UNDEFINED_WRITE_ONLY_%22%7D%7D%7D%5D%2C%22cnonce%22%3A7462007388%2C%22auth-key%22%3A%222709a8e8d717a3a0fbcad62941c00a30%22%7D%7D处的远程资源。(原因:缺少CORS标题“access control allow origin”)。

最佳答案

这是关于配置人员的,只要把适当的配置

关于javascript - 无法从网络服务器恢复json响应,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36400713/

10-12 13:42