刚开始学习ajax虽然我在尝试返回数组中的成功消息时遇到了麻烦.
<script type="text/javascript">
$(function () {
$('#delete').on('click', function () {
var $form = $(this).closest('form');
$.ajax({
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize()
}).done(function (response) {
if (response.success) {
alert('Saved!');
} else {
alert('Some error occurred.');
}
});
});
});
</script>
<?php
$array = array();
$array['success'] = TRUE;
echo $array;
?>
Run Code Online (Sandbox Code Playgroud)
response.success应该引用$ array ['success']正确吗?
I have been reading up on htmlspecialchars() for escaping user input and user input from the database. Before anyone says anything, yes, I am filtering on db input as well as using prepared statements with bindings. I am only concerned about securing the output.
I am confused as to when to use ENT_COMPAT, ENT_QUOTES, ENT_NOQUOTES. I came across the following excerpt while doing my research:
The second argument in the
htmlspecialchars()call isENT_COMPAT. I've used …
试图弄清楚为什么这会返回错误的计数......似乎限制对计数没有影响.
例如...如果找到20台计算机,但我将其限制为10(license = 10),我的返回显示20.
$stmt = $db->prepare("
SELECT count(computer_id)
FROM computers
WHERE account_id = :account_id
ORDER BY computer_id ASC LIMIT 0, :licenses
");
$binding = array(
'account_id' => $_SESSION['user']['account_id'],
'licenses' => $_SESSION['user']['licenses']
);
$stmt->execute($binding);
$results = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
Run Code Online (Sandbox Code Playgroud)
另一方面,这将正确返回10:
$stmt = $db->prepare("
SELECT computer_id
FROM computers
WHERE account_id = :account_id
ORDER BY computer_id ASC LIMIT 0, :licenses
");
$binding = array(
'account_id' => $_SESSION['user']['account_id'],
'licenses' => $_SESSION['user']['licenses']
);
$stmt->execute($binding);
$results = count($stmt->fetchAll(PDO::FETCH_COLUMN, 0));
Run Code Online (Sandbox Code Playgroud) 试图从ul中的最后一个li获取data-id值.它总是返回空.
js:
var ss_id = $('#lightSlider .slides').last().data('id');
Run Code Online (Sandbox Code Playgroud)
ul/li结构:
相同的li结构以不同的数据重复.
<ul id="lightSlider" class="gallery list-unstyled clearfix lightSlider csSlide" style="width: 1124px;">
<li class="slide active" title="(window has no title) " data-thumb="/showimage.php?show=test1.jpg" data-id="30" style="width: 1094px; float: left; margin-right: 30px;">
<img class="img-responsive" title="(window has no title) " src="/showimage.php?show=test1.jpg">
<div style="border-top:1px #dddddd solid; padding:0 15px 15px 15px; background:#f5f5f5;">
<h4><b>Wed, 06/25/14 @ 4:58:24 am UTC</b></h4>
<ul class="list-unstyled">
<li><b>1 :</b> test</li>
<li><b>2 :</b> test</li>
<li><b>3 :</b> test</li>
</ul>
</div>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)