Unable to make php $_REQUEST from XMLHttpRequest data

Viewed 26

I am trying to make XMLHttpRequest from my html frontend to the php microservice backend, sending data from the input to be manipulated, and displayed on html output

The function I am trying to execute is triggered by 'onlick'

Frontend

function markRequired()
{
    input_text = document.getElementById('input-text').value
    input_text2 = document.getElementById('input-text2').value
  

    let xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                var j = JSON.parse(this.response);
                mark_required = j.answer;
        
                displayMark();
            }
        };

       
        xhttp.open("GET",markURL+"?input_text="+input_text+"?input_text2="+input_text2);
        
        xhttp.send();

        return;
    }
}

Backend

<?php
header("Access-Control-Allow-Origin: *");
header("Content-type: application/json");
require('functions.inc.php');


//main array
$inputtext = $_REQUEST['input_text'];

$furthertext = $_REQUEST['input_text2'];

$totalsofar = getTotal($inputtext, $furthertext) // In php unittest the function works, so i know it's not the problem 


$output['string']=$inputtext."=".$answer;
$output['answer']=$totalsofar;

echo json_encode($output);
exit();

Whenever I run my html front end and call the function, markRequired() I am not getting any response. Status code is 200 and I can see the sent data in the request URL.

When I try to return the input string, I am getting a null response.

I can't use cURL for this particular project otherwise I would have.

Any help would be much appreciated!!

0 Answers
Related