PHP變量所以,我有一個有趣的問題jQuery的.load()打破加載到HTML的身體
我有jQuery的.load()函數的問題。我有一個文件結構如下
index.php
|
|---header.html
|---body.html
|---footer.html
index.php文件設置了三個變量,所以$variable_one = new Database('passedQuery');
了header.html,body.html和footer.html然後被納入的index.php
在body.html我有它通過一個通用的jQuery函數提交的body.html類似
<div class="span4 well">
<h3>Current Statistics</h3>
<hr>
<table class="table table-striped">
<thead>
<tr>
<th>Users</th>
<th>Event One</th>
<th>Event Two</th>
<th>Event Three</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $var1->result[0][0]; ?></td>
<td><?php echo $var2->result[0][0]; ?></td>
<td><?php echo $var3->result[0][0]; ?></td>
</tr>
</tbody>
</table>
</div>
東西,我也有一個形式,所以
$(document).ready(function(){
$('.btn').bind('click', function(e){
e.preventDefault();
var form = $(this).parents('form');
var vals = $(form).serialize();
var form_id = $(form).attr('id');
$.ajax({
url: $(form).attr('action'),
type: $(form).attr('method'),
data: vals,
dataType: 'json',
success: function(data){
console.log("Success");
$('#information').html('<div class="alert alert-success">Great Success! :)</div>');
setTimeout(function() {
$('#content').load('views/partials/body.html');
}, 5000);
},
error: function(a, b, c){
console.log("Error");
$('#information').html('<div class="alert alert-error">Epic Failure</div>');
setTimeout(function() {
$('#content').load('views/partials/body.html');
}, 5000);
}
});
});
});
當我提交表單,並重新加載的身體現在在HTML中回顯的PHP變量都走了,我也得到類似以下
[dateTime] [error] [client IP] PHP Notice: Undefined variable: variable in /path/to/body.html on line 133, referer: myReferrer
我問了一個Apache錯誤很少有我的朋友對此感到難過,就像Freenode的#jquery一樣。有人有主意嗎?
更新 - 表單代碼和index.php文件CODE 形式
<div class="span4 well">
<form class="form-horizontal" id="admin_add" name="admin_add" method="post" action="routes/to/add_admin.php">
<fieldset>
<legend>Add Administrator</legend>
<div class="control-group">
<label class="control-label" for="select03">Select a user</label>
<div class="controls">
<select id="select03" name="user">
<?php
foreach($var1->result as $key => $value)
echo "<option>".$value[0]."</option>";
?>
</select>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary form-submit-button">Submit</button>
</div>
</fieldset>
</form>
</div>
指數
$var2 = new Database('query', 'SELECT COUNT(uid) FROM attendees WHERE eid = 1');
$var3 = new Database('query', 'SELECT COUNT(uid) FROM attendees WHERE eid = 2');
/**
* List users to add to database
*/
$var1 = new Database('query', 'SELECT name FROM users WHERE admin=0');
/**
* Include all the visuals
*/
include('views/partials/header.html');
require_once('views/partials/body.html');
include('views/partials/footer.html');
你可以發表你的表格代碼以及 – Kishore
什麼是行133在body.html? –
@DaveM它只是指我在哪裏回顯一個變量,您可以在我的更新示例中看到 – samdunne