如何显示与AJAX / jQuery的打印? [英] How do I show the print with AJAX/jQuery?

查看:100
本文介绍了如何显示与AJAX / jQuery的打印?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想了解这整个AJAX / jQuery的事情。现在,当我单独运行这个PHP脚本,我将不得不等待和观看车轮打滑,直到它的循环完成的,然后它会加载。

So I'm trying to understand this whole AJAX/jQuery thing. Right now, when I run this PHP script alone, I would have to wait and watch the wheel spin until it's done with the loop and then it will load.

while ( $row = mysql_fetch_array($res) ) {
    postcode_to_storm( $row['Test'] );

    $dom = new DOMDocument();
    @$dom->loadHTML($result);
    $xPath = new DOMXPath($dom);

    $failInvite = 'Rejected';
    $findFalse = strpos($result, $failInvite);

    if ( $findFalse == true ) {
        $array[$i] = $row['Test'];
        $i++;
        echo $array[$i]};
    } 

}

现在,我该如何使用AJAX / jQuery来显示呼应$数组[$ i]}; 调用它,而不是等待整个过程完成每次?

Now, how do I use AJAX/jQuery to show echo $array[$i]}; everytime it is invoked instead of waiting for the whole process to complete?

推荐答案

的方式Ajax的工作原理是,与第一个请求,你写你的网页的基本的HTML,其中包括一些javascript调用返回到服务器并要求更多数据。根据您打算如何把你的数据呈现页面时获得更多的数据之后,它可能使一个或多个请求。使用Ajax需要你重新思考你如何提供数据。例如,你需要一脚本载入页面,然后又脚本,以获取数据 - 当然,他们可能是一样的,只是用不同的参数。我将添加一个简单的例子,因为重构你的榜样,需要您的数据更多的理解和它是如何提供证明。这个例子来自 w3schools.com

The way AJAX works is that with the first request you write the basic HTML of your web page, including some javascript that calls back to the server and asks for more data. Depending on how you plan to send your data, it may make one or more requests after the page is rendered to get more data. Using AJAX will require that you rethink about how you're delivering your data. For example, you'll need one "script" to load the page, then another "script" to get the data -- of course, they could be the same, just with different parameters. I'll add a simple example to demonstrate since refactoring your example would require more understanding of your data and how it's delivered. This example is from w3schools.com.

HTML:

<script type="text/javascript">
   $(function() {
       $('#users').change(function() {
          // here's the AJAX bit 
          $.get( '/users/load.php?q=' + $(this).val(),
               function(html) {
                  $('#txtHint').html(html);
          });
       });
   });
</script>
</head>
<body>

<form>
<select name="users">
<option value="">Select a person:</option>
<option value="1">Peter Griffin</option>
<option value="2">Lois Griffin</option>
<option value="3">Glenn Quagmire</option>
<option value="4">Joseph Swanson</option>
</select>
</form>
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>

</body>
</html>

PHP

<?php
$q=$_GET["q"];

$con = mysql_connect('localhost', 'peter', 'abc123');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("ajax_demo", $con);

$sql="SELECT * FROM user WHERE id = '" . mysql_real_escape_string( $q ) . "'";

$result = mysql_query($sql);

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['FirstName'] . "</td>";
  echo "<td>" . $row['LastName'] . "</td>";
  echo "<td>" . $row['Age'] . "</td>";
  echo "<td>" . $row['Hometown'] . "</td>";
  echo "<td>" . $row['Job'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

这篇关于如何显示与AJAX / jQuery的打印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆