当前位置: 首页 > 工具软件 > realm-java > 使用案例 >

realm-js chrome debug 报错解决方案

桑璞
2023-12-01

failed to execute ‘send’ on ‘xmlhttprequest’

方案一:修改node_modules/realm/lib/browser/rpc.js

if (global.__debug__) {
    let request = global.__debug__.require('sync-request');
    let response = request('POST', url, {
      body: JSON.stringify(data),
      headers: {
        "Content-Type": "text/plain;charset=UTF-8"
      }
    });

    statusCode = response.statusCode;
    responseText = response.body.toString('utf-8');
} else {
    let body = JSON.stringify(data);
    let request = new XMLHttpRequest();

    // 增加以下代码
    if (__DEV__) {
        url = 'http://localhost:8083' + url.substring(url.lastIndexOf('/'));
    }

    request.open('POST', url, false);
    request.send(body);

    statusCode = request.status;
    responseText = request.responseText;
}

方案二:修改RealmReactModule.java


两处

response.addHeader("Access-Control-Allow-Origin", "http://localhost:8081");

修改为

response.addHeader("Access-Control-Allow-Origin", "*");

 类似资料: