0

i have a question regarding passing the Content of a PHP Variable to a getJson Request. My Current Code looks like this

    <script type="text/javascript">
    window.onload = function () {
        
            var tool = <?php echo $_REQUEST['tool']; ?>;
            $.getJSON("fertigung/graph/mes/autocomplete/getdata_error_vs_error_category.php?type=json", { tool: $tool }, function(data) {
            var dataPoints = [];
            
            var chart = new CanvasJS.Chart("chartContainer",{
            animationEnabled: true,
                    animationDuration: 2000,
                    exportEnabled: true,
                    zoomEnabled: true,
            title:{
            fontSize: 15,
            text:"Number of Fails vs. Diagnostic Part" 
            },
            axisX: {
                   interval:1,
                    labelMaxWidth: 300,
                    labelAngle: 45,
                    labelFontSize: 12,
                    labelFontFamily: "tahoma",
                },
            axisY: {
                    title: "Number of Failed Diagnostics",
                    labelMaxWidth: 300,                
                    labelFontSize: 12,
                    labelFontFamily: "tahoma",
                },
            data: [{
                type: "column",
                dataPoints : data,
                }]
                });
            
    chart.render();});
}
    </script>

The target is to handover the Content of var tool to the getjson page.

Big Thanks in advance for your help.

Best Regards

Paradoxs

Para Doxs
  • 1
  • 1
  • 1
    `{ tool: $tool }` - your JS variable is named `tool`, not `$tool`. – CBroe Jun 09 '23 at 06:11
  • 1
    `` - massive XSS vulnerability. Plus, will easily cause errors, if that data does not result in valid JS code. You should be using json_encode to pass values from PHP to JavaScript, see https://stackoverflow.com/questions/23740548/how-do-i-pass-variables-and-data-from-php-to-javascript – CBroe Jun 09 '23 at 06:13

0 Answers0