首页 > 解决方案 > 解析 JS 对象以在 PHP 相同文件中处理

问题描述

嗨,我正在学习 javascript,但有点卡住了。我创建了一个 JS 对象,它接收来自各种 url/工作负载的信息。我想获取这个 JS 对象并在 PHP 中进一步处理它(写入 csv 等)。但是我不知道如何将对象从 JS 中取出并放入我的 php.ini 文件中。我将所有内容都放在一个文件中,我不确定这是否是我的问题,很多解决方案都看到了 filegetcontents 等。我可以粘贴我的代码。善良,我是一个雄心勃勃的学习者,但有时会陷入困境,我已经广泛搜索了可能不是正确的东西。我已经阅读了有关解析的建议,但我没有运气让它在一个文件中工作。

<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 +"&paragraph="+paragraph+"&&word="+word);
xhttp3.send();



</script>

<?php

//$mygetter = $_POST['obj'];
//$values = json_decode($mygetter);
//echo $values;

?>

标签: javascriptphp

解决方案


推荐阅读