Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用依赖于环境的api url调用AJAX Jquery_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 使用依赖于环境的api url调用AJAX Jquery

Javascript 使用依赖于环境的api url调用AJAX Jquery,javascript,jquery,ajax,Javascript,Jquery,Ajax,我正在尝试从JQuery代码中重构,该代码目前看起来如下: $.ajax({ type: 'POST', //change to API_URL + '/login' url: 'localhost:8080/login', data: data, crossDomain: true, beforeSend: function(xhr){ xhr.withCredent

我正在尝试从JQuery代码中重构,该代码目前看起来如下:

    $.ajax({
        type: 'POST',
        //change to API_URL + '/login'
        url: 'localhost:8080/login',
        data: data,
        crossDomain: true,
        beforeSend: function(xhr){
            xhr.withCredentials = true;
        },
        success: function(data, textStatus, request) {
            
        },
        error: function(xhr, textStatus, errorThrown) {

        }
    });
我想将“localhost:8080”更改为API_URL,这是环境特定的,具体取决于我是在本地运行应用程序还是在生产环境中运行应用程序。我尝试使用环境变量,然后通过process.env.API_URL访问API_URL,但我一直得到“process is undefined”,从浏览器访问环境变量似乎不安全-如何在jquery中访问.env文件

关于如何做到这一点,还有其他建议吗

谢谢