从一个正在运行的PHP代码中,了解如何更新DIV标记中的状态
From a running PHP Code, how to update status in DIV tag
我有一个网页,我在其中循环下载一个又一个数据。每次数据下载完成后,我想将状态更新为网页中的DIV标记。我怎么能做到这一点。连接到服务器并通过php代码下载数据,div标记位于.phtml页面中。
我试过
echo "
<script type='"text/javascript'">
$('#tstData').show();
</script>
";
但是echo语句的更新只会在最后发生。DIV标签的刷新需要在每次下载结束时进行。
使用jQuery加载()
$('#testData').load('http://URL to script that is downloading and formatting data to display');
$("#save_card").submit(function(event) {
event.preventDefault();
var url = "card_save.php"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
dataType:"json",
data: $("#save_card").serialize(), // serializes the form's elements.
success: function(data)
{
console.log(data);
if(data.msg=="success")
{
$("#submit_msg").html("Thank You !!!");
console.log("Record has been Inserted Successfully!!!");
}
else
{
$("#submit_msg").html(data.er);
console.log("There Is Some Error");
}
$("#submit_msg").show();
setTimeout(function() { $("#submit_msg").hide(); }, 5000);
$("#save_card").get(0).reset();
}
});
return false; // avoid to execute the actual submit of the form.class_master
});
使用此Ajax函数可以调用PHP函数来获取数据。此处
#save_card
=要提交的表单的Id。url=表单的操作或数据来源的php文件的位置。
data: $("#save_card").serialize()
=它以串行形式发送表单的所有数据。可以手动创建数据来完成此操作,并使用data: {'name':name,'year':year}
重新填充此行function(data)
=此处数据以json格式从php代码返回。data.msg
=这是一种从数据访问不同字段的方式。$user_email = $_REQUEST['user_email']; $cat_id = $_REQUEST['category']; $title = $_REQUEST['title']; $country = $_REQUEST['country']; $date = date("Y-m-d H:i:s"); $sql = "INSERT INTO project(title, user_email, cat_id, country, start_date) VALUES ('$title','$user_email','$cat_id','$country', '$date')"; if (mysql_query($sql)) { $project_id = mysql_insert_id(); echo json_encode(array('project_id' => $project_id, 'msg' => 'Successfully Added', 'status' => 'true')); } else { echo json_encode(array('msg' => 'Not Added', 'status' => 'false')); }
以json格式发送数据的PHP代码
相关文章:
- 添加文字和评论功能更新Div
- 在Rails中更新Div,而不更改更新请求后的视图
- 根据CHECKBOX输入值动态更新DIV信息
- JavaScript on点击更新Div
- 使用不同的API参数更新DIV内容
- 从一个正在运行的PHP代码中,了解如何更新DIV标记中的状态
- 使用2个表单的SQL查询更新DIV
- Rails 在 JavaScript 调用后更新 DIV(从模型重新加载)
- 单击时更新 DIV 内容,而无需直接知道其 ID
- 可观测集合发生变化时更新Div
- 更新DIV的泛型函数
- 点击使用jQuery用HTML更新DIV
- 在jQuery上更新Div隐藏字段可排序拖放更新
- 如何更新DIV的内容
- 更新Div内文本的问题
- 使用来自ASP的数据更新DIV内容.NET上的事件
- 如何更新Div内的文本
- 更新DIV并在1秒后使用setTimeout再次清空它
- 基于顶部位置更新Div的类名
- 更新Div/PartialView上的Interval