I can not get the PHP echo in my Ajax.
This is my test01.html code:
In my HTML code, I quote the jQuery, and I bind the event in my "sub01" button, I use Ajax provide the POST request:
$(".sub01").bind("click", function() {
$.ajax({
type: "POST",
url: "cms/test01.php?action=test01",
dataType: "json",
data: {
"var_01": "var_01_value",
"var_02": "var_02_value",
},
success: function(response) {
console.log(response) // there I want to console the response from PHP.
}
})
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<form>
<input type="text" value="var_01">
<input type="text" value="var_02">
<input id="sub01" type="submit" value="click me!">
</form>
</div>
And this is my PHP test01.php code:
in my PHP code I want to echo the $_POST, then I want the AJAX code get the response.
<?php
echo $_POST;
I want the code
success: function(response) {
console.log(response) // there I want to console the response from PHP.
}
shows the PHP echo, but there console nothing.
echo$_POSTas$_POSTis an array, thus this will result in a notice. Go withvar_dump($_POST)echo $_POSTdoesnt make sense, it will just printArray. You´d have to use$_POST['var_01']or var_02$.ajaxcall is what sends the data to the server, and in there it is specified that the request method is to be POST.