【发布时间】:2014-02-01 00:11:56
【问题描述】:
这是我的html代码
<input type="text" name="query_post" id="textid" />
<input type="button" class="gbutton" style="-webkit-user-select: none; opacity:1 " id="shareImageButton" value="Share" onclick="Postquery()">
<div id="new_query_post">
</div>
css
.new_query_post{
display:inline;
}
js
function Postquery() {
// 1. Create XHR instance - Start
var xhr;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
}
else {
throw new Error("Ajax is not supported by this browser");
}
// 1. Create XHR instance - End
// 2. Define what to do when XHR feed you the response from the server - Start
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status == 200 && xhr.status < 300) {
document.getElementById('new_query_post').innerHTML = xhr.responseText;
}
}
}
// 2. Define what to do when XHR feed you the response from the server - Start
var textid = document.getElementById("textid").value;
// 3. Specify your action, location and Send to the server - Start
xhr.open('POST', 'postquery.php');
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("textid=" + textid);
// 3. Specify your action, location and Send to the server - End
}
php
<?php
$textid =trim($_POST["textid"]);
echo"
<div id='each_query'>
<span style='margin-top:1%; margin-left:3%;float:left;color: #3bb598'>Jan 26'14 </span>
<span style='margin-top:1%; margin-right:3%;float:right;color: #3bb598'>Hits : 39 Views : 60</span>
<br>
<table><tr>
<th><img src='propic/pro_pic.jpg' id='img' align='top'><br><span style='color:#3bb598'>Title</span> <br><span style='color:#3bb598'><a href='' id='tagid'>Travel</a></span></th>
<th></th><th></th><th></th>
<th style='text-align: justify;color: #212121;'>".$textid."
</th><th></th><th></th><th></th>
</tr></table>
</div>
";
?>
我希望新查询应该以淡入淡出效果发布,并且应该在发布之前显示一些 ajax 加载......
【问题讨论】:
-
既然您使用的是 jQuery(标记),为什么不使用
$.ajax和$('.el').fadeIn()? -
如何..???...帮我写代码.....
标签: javascript php jquery css ajax