我正在尝试将 laravel .env 变量包含到我的 js 文件中,我的文件名是 custom-script.js,我的 js 代码是:
function sendBusinessDetails(postForm) {
$.ajax({//Process the form using $.ajax()
type: 'post', //Method type
url: 'http://localhost:8000/Process', //Your form processing file URL
data: postForm, //Forms name
dataType: 'json',
我的 .env 文件包含
APP_URL=http://localhost:8000
我如何替换 APP_URL= http://localhost:8000进入我的网址:'http://localhost:8000/Process ',
非常感谢您的帮助
$.ajax({
type: 'post', //Method type
url: '{{env("API_URL")}}/api/apikey?api_key
最佳答案
在你的 blade
文件中:
<script>
var action = "{{ env("APP_URL") }}"
</script>
在你的 js
中:
url : action+'/process',
关于php - 如何将 laravel ..env 变量包含到 js 文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50035620/