[英]simple jquery .post not returning data
jQuery语句:
$.post ('test.php', {f1: 'abc', f2: 'def'}, function (data) {console.log (data)})
test.php的:
<?php
$f1 = $_REQUEST ['f1'];
$f2 = $_REQUEST ['f2'];
echo $f1 . $f2;
?>
调用jquery语句后,未返回任何内容,该内容应在控制台区域中看到。
但是,运行test.html,浏览器将按预期显示“ f1f2”。 的test.html:
<form action='test.php' method="post">
<label>f1</label>
<input name="f1" type="text">
<label>f2</label>
<input name="f2" type="text">
<input type="submit">
</form>
为什么没有返回数据到jquery post请求?
这应该工作:
<?php
$f1 = $_POST ['f1'];
$f2 = $_POST ['f2'];
echo $f1 . $f2;
?>
并且如果您想使用jquery进行发布,则不要提交表单,在Submit上使用preventDefault,并触发发布。
$("#yourFormId").submit(function(e){e.preventDefault();$.post ('test.php', {f1: 'abc', f2: 'def'}, function (data) {console.log (data)})})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.