将Javascript数组传递给php函数并使用ajax调用另一个php函数
我这里有这个按钮来调用Javascript函数
<button class=" btn-primary border border-primary rounded p-2 ms-auto " id="proceed" onclick="proceed_tags()">Proceed </button>
该函数是将selected_keywords_arr数组传递到controller/keywords_suggestion.php
function proceed_tags(){
if (selected_keywords_arr === undefined || selected_keywords_arr.length == 0) {
// array empty or does not exist
alert("you have to select keywords first");
return;
}
var Tags_Data = JSON.stringify(selected_keywords_arr);
alert("button clicked");
$.ajax({
type: "POST",
url: 'controller/keywords_suggestion.php',
data:{action,Tags_Data },
success:function(Success) {
alert(Success);
}
});
}
这里的controller/keywords_suggestion.php
我试图捕获数组并检查单击按钮是否执行另一个函数 但它打印此错误 [Wed Mar 16 18:16:59.919632 2022] [php:warn] [pid 7488:tid 1852] [client ::1:65035] PHP 警告:C:\\xampp\ 中未定义的数组键“action” \htdocs\\seosystem\\controller\\keywords_suggestion.php 第 25 行
$keyword_tags_arr = json_decode($_POST['action'],true);
if(isset($_POST["action"])){
var_dump($keyword_tags_arr);
echo " <script type=\"text/javascript\"> alert(\"Helllllo\"); ";
$Keywords_analysis_objj = new Keywords_analysis();
$Keywords_analysis_objj->Keywords_title_desc();
}
I have this button here to call Javascript function
<button class=" btn-primary border border-primary rounded p-2 ms-auto " id="proceed" onclick="proceed_tags()">Proceed </button>
The function is to pass selected_keywords_arr Array to controller/keywords_suggestion.php
function proceed_tags(){
if (selected_keywords_arr === undefined || selected_keywords_arr.length == 0) {
// array empty or does not exist
alert("you have to select keywords first");
return;
}
var Tags_Data = JSON.stringify(selected_keywords_arr);
alert("button clicked");
$.ajax({
type: "POST",
url: 'controller/keywords_suggestion.php',
data:{action,Tags_Data },
success:function(Success) {
alert(Success);
}
});
}
here in controller/keywords_suggestion.php
I'm trying to capture the array and to check if the button clicked to execute another function
but it prints this error[Wed Mar 16 18:16:59.919632 2022] [php:warn] [pid 7488:tid 1852] [client ::1:65035] PHP Warning: Undefined array key "action" in C:\\xampp\\htdocs\\seosystem\\controller\\keywords_suggestion.php on line 25
$keyword_tags_arr = json_decode($_POST['action'],true);
if(isset($_POST["action"])){
var_dump($keyword_tags_arr);
echo " <script type=\"text/javascript\"> alert(\"Helllllo\"); ";
$Keywords_analysis_objj = new Keywords_analysis();
$Keywords_analysis_objj->Keywords_title_desc();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论