javascript - 解析 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 +"¶graph="+paragraph+"&&word="+word);
xhttp3.send();
</script>
<?php
//$mygetter = $_POST['obj'];
//$values = json_decode($mygetter);
//echo $values;
?>
解决方案
推荐阅读
- visual-studio-code - 使用全屏VSCode时如何隐藏侧边栏和活动栏?
- c# - 支持多个版本的第三方库
- python - 将 matplotlib 保存为最终给定大小,包括标题
- robotframework - 当在机器人框架中找不到元素时,如何在测试期间在控制台中显示消息?
- c# - .net 核心 webapi 项目中的 WebHost 变量来自哪里?
- twitter-bootstrap-3 - 引导 3 到 4 模态灯箱坏了
- c# - 如何修复过时的 ILoggerFactory 方法?
- ruby-on-rails - 预编译资产失败 Heroku Rails
- asp.net-core - 无法通过 IRouter 更改目标控制器/动作
- jquery - 在 jquery modal popup 中获取 asp:repeater 中标签的值