http://pastebin.com/dttyN3L6
我从来没有真正使用过jquery / js所以我不确定如何做到这一点或者我会把代码放在哪里.
它与setInterval(loadLog,2500)有关;
$.ajax({ type: "POST",url: "upload.PHP",data: dataString,success: function() { } }); return false; `
和
<?PHP $conn1 = MysqLi_connect('xxx') or die('Error connecting to MysqL server.'); $sql = "SELECT * from text ORDER BY id DESC LIMIT 1"; $result = MysqLi_query($conn1,$sql) or die('Error querying database.'); while ($row = MysqLi_fetch_array($result)) { echo '<p>' . $row['words'] . '</p>'; } MysqLi_close($conn1); ?> </div> <?PHP if (!isset($_SESSION["user_id"])) { } else { require_once('form.PHP'); } ?>
您可以在不刷新页面的情况下提交表单,如下所示:
原文链接:https://www.f2er.com/php/137012.htmlform.PHP的:
<form action='profile.PHP' method='post' class='ajaxform'> <input type='text' name='txt' value='Test Text'> <input type='submit' value='submit'> </form> <div id='result'>Result comes here..</div>
profile.PHP:
<?PHP // All form data is in $_POST // Now perform actions on form data here and // create an result array something like this $arr = array( 'result' => 'This is my result' ); echo json_encode( $arr ); ?>
jQuery的:
jQuery(document).ready(function(){ jQuery('.ajaxform').submit( function() { $.ajax({ url : $(this).attr('action'),type : $(this).attr('method'),dataType: 'json',data : $(this).serialize(),success : function( data ) { // loop to set the result(value) // in required div(key) for(var id in data) { jQuery('#' + id).html( data[id] ); } } }); return false; }); });
如果你想在特定时间之后调用ajax请求而不刷新页面,你可以尝试这样的事情:
var timer,delay = 300000; timer = setInterval(function(){ $.ajax({ type : 'POST',url : 'profile.PHP',data : $('.ajaxform').serialize(),success : function(data){ for(var id in data) { jQuery('#' + id).html( data[id] ); } } }); },delay);
你可以随时停止计时器,如下所示:
clearInterval( timer );
希望这能为您提供完成任务的方向.