我似乎遇到了我的jQuery脚本问题.我想用新的"tbody"内容替换当前的"tbody"内容.目前,它只是继续添加到当前数据,而不是删除旧数据和插入新数据.有任何想法吗?
这是我的代码:
function getData(action,searchVal) {
$.get('ajax.php',{action:action,value:searchVal}, function(data){
var json = jQuery.parseJSON(data);
$(function () {
var content = '';
content += '<tbody>';
for (var i = 0; i < json.length; i++) {
content += '<tr id="' + json[i].ID + '">';
content += '<td><input id="check_' + json[i].ID + '" name="check_' + json[i].ID + '" type="checkbox" value="' + json[i].ID + '" autocomplete=OFF /></td>';
content += '<td>' + json[i].ID + '</td>';
content += '<td>' + json[i].Name + '</td>';
content += '<td>' + json[i].CountryCode + …Run Code Online (Sandbox Code Playgroud) 我正在为我的垃圾收集公司开发路线追踪/优化软件,并希望对我目前的数据结构/情况提供一些反馈.
这是我的MongoDB结构的简化版本:
数据库:数据
类别:
"客户" - 包含所有客户数据的数据收集.
[
{
"cust_id": "1001",
"name": "Customer 1",
"address": "123 Fake St",
"city": "Boston"
},
{
"cust_id": "1002",
"name": "Customer 2",
"address": "123 Real St",
"city": "Boston"
},
{
"cust_id": "1003",
"name": "Customer 3",
"address": "12 Elm St",
"city": "Boston"
},
{
"cust_id": "1004",
"name": "Customer 4",
"address": "16 Union St",
"city": "Boston"
},
{
"cust_id": "1005",
"name": "Customer 5",
"address": "13 Massachusetts Ave",
"city": "Boston"
}, { ... }, { ... }, …Run Code Online (Sandbox Code Playgroud) 我是一个PHP phr34k沉迷于JavaScript寻求一些知识.如果要在他们的脚本中包含php代码,那么最好的方法是什么?我提供了一些示例代码作为我将如何在脚本中包含PHP的示例.
这是一种有效的方法吗?
的index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP with JavaScript?</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="test.js.php"></script>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
test.js.php
<?php
$foo = 'bar';
?>
$(document).ready(function() {
var foo = '<?php echo $foo; ?>';
alert(foo);
});
Run Code Online (Sandbox Code Playgroud)
再次感谢!