Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我希望我的ajax代码应该带有fadeIn效果_Javascript_Php_Jquery_Css_Ajax - Fatal编程技术网

Javascript 我希望我的ajax代码应该带有fadeIn效果

Javascript 我希望我的ajax代码应该带有fadeIn效果,javascript,php,jquery,css,ajax,Javascript,Php,Jquery,Css,Ajax,这是我的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_p

这是我的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>
js

php


我希望新的查询应该以fadeIn效果发布,并且在发布之前应该显示一些ajax加载……

使用jQuery的帖子可能会更简单:

var jqXhr = function(e) {
  var $id = $('#textid').val();
  var $spinner = $('#spinner');
  var $result = $('#new_query_post');
  e.preventDefault();
  $result.fadeOut(200);
  $spinner.show();
  $.post('postquery.php', { textid: $id }, function(response) {
    $result.html(response).fadeIn(200);
    $spinner.hide();
  });
}
$('#shareImageButton').on('click', jqXhr);

并添加一个。。。在您的HTML中,您可以找到一些纯CSS微调器的示例。

既然您使用的是带标签的jQuery,为什么不使用$.ajax和$.el.fadeIn?如何…?…帮助我编写代码…不工作…可能是我做得不对…我需要更改我的php代码吗。。。。
    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 


     $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&nbsp;&nbsp; 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>

                ";

     ?>
var jqXhr = function(e) {
  var $id = $('#textid').val();
  var $spinner = $('#spinner');
  var $result = $('#new_query_post');
  e.preventDefault();
  $result.fadeOut(200);
  $spinner.show();
  $.post('postquery.php', { textid: $id }, function(response) {
    $result.html(response).fadeIn(200);
    $spinner.hide();
  });
}
$('#shareImageButton').on('click', jqXhr);