[英]How to get data from '$.post' in a localhost php file?
I'm building an extension that extracts DOMs from a website(not mine) and automates a button click with filling some inputs. 我正在构建一个扩展程序,该扩展程序从网站(不是我的网站)中提取DOM,并自动完成一些输入,从而实现了按钮单击的自动化。
I made a local database which the extension will be extracting values from to fill the inputs, I could successfuly done that with xmlhttprequest that reads my php file from my content-script js file. 我创建了一个本地数据库,该扩展名将从中提取值以填充输入,我可以使用xmlhttprequest成功地做到这一点,该xmlhttprequest从我的内容脚本js文件读取我的php文件。
Now I want to send my php file that the button was clicked so it updates the database with new values. 现在,我想发送单击该按钮的php文件,以便它用新值更新数据库。 I tried $.post() but I can't get it with $_POST[];
我试过$ .post(),但不能用$ _POST []来得到;
content-script.js 内容的script.js
setTimeout(
function(){
var finsih_div_found = $(dialog_div_found).find("div").get(12);
var finish_button_found = $(finsih_div_found).find("button").get(2);
finish_button_found.dispatchEvent(new Event('click', {bubbles: true}))
$.post('http://localhost:8012/extension-Oasis/php/getIntervenant.php', {button: 'Clicked'}, function(e){
console.log("posted");
});
},2000);
php file php文件
$status = $_POST["button"]; //Gives an error of 'Undefined index: button'.
Please note that the website is not mine I don't have nor the back end nor the front end nor its API's. 请注意,该网站不是我所没有的,也不是后端,前端,也不是其API。 I just want to automate a button click that's done regularly.
我只想自动化常规执行的按钮单击。
Have you called your PHP file directly? 您是否直接调用过PHP文件? Then it is a HTTP GET request and therefore $_POST['button'] throws and 'Undefined index: button' error.
然后,这是一个HTTP GET请求,因此$ _POST ['button']引发并且出现“ Undefined index:button”错误。 In other words, you can only access the button value via $_POST[] if you use your jQuery $.post to do so.
换句话说,如果使用jQuery $ .post,则只能通过$ _POST []访问按钮值。
$.post('http://localhost:8012/extension-Oasis/php/getIntervenant.php', {button: 'Clicked'}, function(e){
console.log(e); // log everything that is echoed in PHP file to browser's console
});
In your PHP file, add a echo $status;
在您的PHP文件中,添加
echo $status;
in the last line. 在最后一行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.