Hi I have learning javascript and a little bit stuck. I have a JS object created that recieves information from various urls/ workloads. I want to take this JS object and further process it in PHP(write to csv etc). However I don't know how to get the object out of JS and into my php. I have everything in the one file and Im not sure if thats my issue alot of solutions have seen have filegetcontents etc. I can paste in my code. Be kind I am an ambitious learner but sometimes get so stuck I have googled extensively perhaps not the right things though. I have read suggestions about parsing but I haven;t had luck making it work in the one file.
<script type="text/javascript">
/tests occurance of keyword
const before3 = new Date();
let xhttp3 = new XMLHttpRequest();
xhttp3.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var c = JSON.parse(this.response);
resultcount3 = c.answer;
console.log(resultcount3);
const now3 = new Date();
diff3 =now3-before3;
//check = occurance of key word in string
function countWordAppearance(string, word){
return string.split(word).length-1;
}
resultLocal3=countWordAppearance(paragraph.toLowerCase(),word.toLowerCase());
console.log("this result 3" +resultLocal3);
if (resultcount3===resultLocal3){
test3 ='Passed';
} else {
test3 = 'Failed';
}
console.log("Paragraph :" +paragraph + " word :" + word + " result " + resultLocal3 + " Response Time (milliseconds) :"+ diff3);
var testKeyWordAppearance = {
"paragraph": paragraph,
"word": word,
"result Local": resultLocal3,
"result": resultcount3,
"responseT": diff3,
"Test" : test3
};
console.log(testKeyWordAppearance);
//var json_kwc =$parseJson(testKeyWordAppearance);
//$.post("testcorrectness.php", {obj:json_kwc});
}
};
xhttp3.open("GET",proxyURL+"?service="+3 +"¶graph="+paragraph+"&&word="+word);
xhttp3.send();
</script>
<?php
//$mygetter = $_POST['obj'];
//$values = json_decode($mygetter);
//echo $values;
?>