English 中文(简体)
A. 反应舱中的出口常态,这些反应器数据是从综合系统文档中混合的。
原标题:Export constant in react js whom data is comming from php file

I am using Php with react js ,there is constant declared in react js constant file that is used all over the application ,initially it was hardcoded in react js like Export const thumburl="www.example.com"; and its imported in almost every part of application now the requirement is to generate this URL dynamically from db.so i created a php file which will return this url i want to use it in react js constant file and export that ,tried several things but wasn t able to get results. it would be great help if any one can provide me the full working method to do this Note : react js is not my domain

async function githubUsers() {
    let response = await fetch( https://example.com/api.php )
    let users = await response.json()
    return users;
}

export const thumbUrl=githubUsers();

tried above code but it couldn t assign the value below is the sample php code

     <?php
if (isset($_SERVER[ HTTP_ORIGIN ])) { 
        header("Access-Control-Allow-Origin: {$_SERVER[ HTTP_ORIGIN ]}");
        header( Access-Control-Allow-Credentials: true );
        header( Access-Control-Max-Age: 86400 );    // cache for 1 day
    }
    if ($_SERVER[ REQUEST_METHOD ] ==  OPTIONS ) {
        if (isset($_SERVER[ HTTP_ACCESS_CONTROL_REQUEST_METHOD ]))
            header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS"); 
        if (isset($_SERVER[ HTTP_ACCESS_CONTROL_REQUEST_HEADERS ]))
            header("Access-Control-Allow-Headers: {$_SERVER[ HTTP_ACCESS_CONTROL_REQUEST_HEADERS ]}");
    }
    $data =  www.example.com/gallery/thumbs/ ;
    header( Content-Type: application/json );
    echo json_encode($data);
问题回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签