簡體   English   中英

如何從本地php文件中的'$ .post'獲取數據?

[英]How to get data from '$.post' in a localhost php file?

我正在構建一個擴展程序,該擴展程序從網站(不是我的網站)中提取DOM,並自動完成一些輸入,從而實現了按鈕單擊的自動化。

我創建了一個本地數據庫,該擴展名將從中提取值以填充輸入,我可以使用xmlhttprequest成功地做到這一點,該xmlhttprequest從我的內容腳本js文件讀取我的php文件。

現在,我想發送單擊該按鈕的php文件,以便它用新值更新數據庫。 我試過$ .post(),但不能用$ _POST []來得到;

內容的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文件

$status = $_POST["button"]; //Gives an error of 'Undefined index: button'.

請注意,該網站不是我所沒有的,也不是后端,前端,也不是其API。 我只想自動化常規執行的按鈕單擊。

您是否直接調用過PHP文件? 然后,這是一個HTTP GET請求,因此$ _POST ['button']引發並且出現“ Undefined index:button”錯誤。 換句話說,如果使用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
    });

在您的PHP文件中,添加echo $status; 在最后一行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM