我有以下两个文件:
<?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
<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);
});
});
将数据类型html
作为第三个参数添加到$.post
-http://api.jquery.com/jQuery.post/
$.post("index.php", function (data) {
alert(data);
}, 'html');