我的目标是在WordPress中创建最简单的ajax调用,但我不知道它是如何工作的。
JS文件:
jQuery("#votepostform").submit(function() {
var url = "file.php"; // php script to handle form
jQuery.ajax({
type: "POST",
url: url,
data: jQuery("#votepostform").serialize(), // serializes the form\'s elements.
success: function(data)
{
alert(data); // show response from the php script.
}
});
return false; // avoid to execute the actual submit of the form.
});
表单HTML:<form action="" method="post" id="votepostform" />
<input type="hidden" name="postid" value="333" />
<button type="send" name="vote" class="vote_link"></button>
</form>
文件。php:echo \'<script language=\\\'javascript\\\'>alert(\\\'It works! \\\');</script>\';
如何使此ajax代码在WordPress站点中工作?