我有一个带有表单的html页面,在该页面中,我希望提交一个值并使用javascript (w/jquery & ajax)将其发送到出现某个进程的php页面,我希望通过将变量多次发送回原始html页面(可能是空的div (id=txtHint) )来跟踪该页面。下面是我到目前为止..。
me.html
<html>
<head>
<title>Generator</title>
<script src="jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="howdy.js" type="text/javascript"></script>
</head>
<body>
<div id="form_container">
<h1>Generator</h1>
<form id="myForm" name="myForm">
<input id="myStr" type="text">
<input id="regrForm" type="button" name="submit" value="Submit">
</center>
</form>
</div>
<div id="txtHint"></div>
</body>
</html>howdy.js
$(document).ready(function() {
$("#regrForm").click(function(){
var myText = $("#myStr").val();
$.ajax({
url: 'tracker.php',
type: 'POST',
data: {
newStr: myText},
dataType: "text",
success: function(data){
console.log("It went through!");
$('#txtHint').html(data);
}
});
});
});tracker.php
<?php
$myName = $_POST['newStr'];
echo "<p> My string is: " . $myName . "</p>";
for ($i=0; $i<1000000; $i++){
//analyze stuff
if ($i % 100000 === 0){
echo "Total number of things analyzed: " . $i . " from " . $myName;
}
}
?>问题是,我并不完全确定变量是否从javascript适当地传递到php,以及如何将php更新(我通过$i进行的迭代)准确地传递回html page...any思想?如果我没有提供足够的信息,请告诉我。我很感谢你能提供的任何建设性帮助。
发布于 2015-08-03 22:04:29
用于开发目的的AJAX。
看看您的PHP代码,看起来您将崩溃浏览器您运行的for循环一百万次.然后每一万次打印一次“分析物品总数.”
你到底想达到什么目的?
发布于 2015-08-03 22:11:21
您的变量正在从javascript传递到php。只需将成功函数更新为如下所示
success: function(data)
{
$('#txtHint').html(data);
console.log("It went through!");
}结果将在"#txtHint“节点中打印。
发布于 2015-08-03 21:58:10
有几件事要注意:
</center>。dataType: "text",试着移除它https://stackoverflow.com/questions/31797306
复制相似问题