我想发送一个POST请求到我的PHP文件来处理它并将数据存储在数据库中..我很沮丧,因为$ _POST保持空,无论我尝试什么..
有人可以帮我发送帖子请求并帮我处理它吗?
我的axios请求:
// Performing a POST request
axios.post('dev/api/post.php',{ text: text, unk: unk})
.then(function(response){
console.log(response);
}).catch(function (error) {
console.log(error);
});
Run Code Online (Sandbox Code Playgroud)
这是我在PHP中尝试过的,有些代码被注释掉,因为不确定它是否有用..
if(isset($_POST) && !empty($_POST)){
/*
$jsonReceiveData = json_encode($_POST);
$json_output = json_decode($jsonReceiveData);
$task = $json_ouput->text;
$uniquekey = $json_output->unk;
*/
echo $_POST;
/*
$stmt = $pdo->prepare("INSERT INTO todo (id, tekst, uniquekey) VALUES ('', :tekst, :unk)");
$stmt->bindParam(':unk', '1');
$stmt->bindParam(':tekst','testing');
$stmt->execute();
*/
Run Code Online (Sandbox Code Playgroud)
}
解:
$data = json_decode(file_get_contents("php://input"), true);
$task = $data['text'];
Run Code Online (Sandbox Code Playgroud)
该对象在php:// input中找到
我在我的主页上加载我的JavaScript文件,然后导航到我需要onclick功能的页面.onclick附加到通过AJAX调用随时间动态加载的内容.我试图达到的元素构造如下:
<a href="#" id="query_2" class="list-group-item query">Alle huurdergegevens</a>
Run Code Online (Sandbox Code Playgroud)
在我的JavaScript文件中,我写了这个:
$(".query").click(function() {
var id = $(this).attr('id');
id = id.replace(/\D/g,'');
console.log(id);
exeSQL(id);
});
Run Code Online (Sandbox Code Playgroud)
当我点击元素时,字面上没有任何反应..没有任何记录在控制台,没有错误以及..无法弄清楚我做错了什么...
我在下面发布了我的代码,我想要做的是选择单击按钮下方的'p'元素.我尝试了几个选择器,但我没有成功的任何选择器......
这是我的HTML:
<button class="accordion">Section 1</button>
<div class="panel">
<p>Lorem ipsum...</p>
</div>
<button class="accordion">Section 2</button>
<div class="panel">
<p>Lorem ipsum...</p>
</div>
<button class="accordion">Section 3</button>
<div class="panel">
<p>Lorem ipsum...</p>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的jQuery:
var container = $("#container");
var allPanels = $(".panel");
var acc = $(".accordion");
var active = $(".active");
$(document).ready(function(){
$(".panel:first").show();
$(".accordion:first").toggleClass("active");
acc.click(function() {
active.toggleClass("active");
$(this).toggleClass("active");
allPanels.hide();
$(this).children('p').children('p').first().show();
//The above selector is wrong.
});
});
Run Code Online (Sandbox Code Playgroud) 我正在使用AJAX来检索某个HTML元素的ID.HTML ID的构造类似于"sqlitem_1","sqlitem_2","sqlitem_3"等,每个数字对应于数据库中的记录.
我试过我需要切割的字符串preg_replace('/\D/', '', $item);在哪里$item,但这并没有成功.