PHP arrays into javascript arrays

前端 未结 6 567
伪装坚强ぢ
伪装坚强ぢ 2021-01-17 01:41

I am a bit confused here on how I implement an array into JS from PHP....

I\'m doing this for testing - eventually I\'ll use long polling or websockets if they get h

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-17 02:27

    I agree with the answer in your comments. I would make an AJAX call to yourFile.php and then send back your JSON encoded response. so here would be my psuedo code.

    1. Make AJAX request
    
    $.ajax({
        url: "yourFile.php",
        dataType: 'json',
        success: function(data)
        {
             console.log(data);
        }
    });
    
    2. Make sure that your PHP file also returns header for JSON
    
    header('Content-type: application/json');
    
    2. Return {"x":"283","y":"99","sid":"1"} as data on your ajax request
    
    
    3. call the values by using data.x or data.y or data.sid
    

提交回复
热议问题