我想用ajax解析参数......是不是很可能?如果是这样,我怎么能这样做呢?
HTML / JS
<script>
function myAjax() {
$.ajax({
type: "POST",
url: '/ajax.php',
data:{action:'follow'},
success: function() {
console.log("called");
}
});
}
</script>
<button type='button' name='follow' id='follow' onclick='myAjax()'>Follow @<?php echo $profile ?></button>
ajax.php:
session_start();
require_once 'init.php';
if($_POST['action'] == 'follow') {
User::follow($conn, $_SESSION["name"], $profile);
// $conn is a db connection, $profile is the param I would like to parse through
} else {
echo 'no req';
}
答案 0 :(得分:0)
function myAjax(obj) {
$.ajax({
type: "POST",
url: '/ajax.php',
data:obj,
success: function() { console.log("called"); }
});
}
像这样使用:
myAjax({action:" follow",id:1234});