我尝试在 jquery 代码中使用 Post 方法,但由于某种原因它使用 Get 方法。我正在 WordPress 框架下工作,该框架已将“$”函数重命名为 jquery,然后我将其重命名为 $j。谁能帮我完成这个简单的功能?
$j.ajax({
method: "POST",
url: "extension/marker.php",
data: "series=test",
dataType: "text",
success: function(data){
$j("#text").text(data);
console.log('success' + data);
}
});
PHP 文件:
<?php
if($_POST['series'] == "test")
echo 'yay!';
if($_GET['series'] == "test")
echo 'boo!';
?>
最佳答案
方法:“POST”
应为类型:“POST”
。请参阅the docs .
type
Default: 'GET'
The type of request to make ("POST" or "GET"), default is "GET". Note: Other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not supported by all browsers.
关于php - Ajax 是 "Getting"而不是 "Posting",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2206145/