[英]JQuery post does not work issue
我有以下2个文件:
<?php
?>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function () {
$("form").submit(function () {
var textu = $("#textu").val();
$.post("index.php", function (data) {
alert(data);
});
return false;
});
});
<script>
<form method="post" action="">
<input type="text" id="textu" name="textu">
<input type="submit" value="send" id="send">
</form>
现在,我要设置从值发送到的index.php
返回的数据的样式。
问题是,如果我在文件index.php
使用<h1>
类的东西或任何html标记,则测试文件只会将其作为纯文本返回,例如<h1>text</h1>
。
我想对来自index.php
的数据进行样式设置,但我无法做到这一点,因为它不断向我返回纯文本,并且在该文件中我无法使用任何html标记或PHP以外的任何东西。 我怎样才能做到这一点 ? 有任何想法吗 ?
将数据类型html
作为第三个参数添加到$.post
- http: $.post
$.post("index.php", function (data) {
alert(data);
}, 'html');
尝试这个:
html
<input type="text" id="textu" name="textu">
<input value="send" id="send">
jQuery的:
$("#send").click(function(){
var textu = $("#textu").val();
$.post("index.php",{"textu":textu},function(data){
alert(data);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.