如何检查jQuery.ajax()请求标头状态是否为"304 Not Modified"?
jqXHR.status通常返回200,即使请求的标题是"304 Not Modified".
ifModified:true 没有太多帮助,因为它破坏了XHR数据请求.
有没有办法返回PHP json_encode编码UTF-8而不是Unicode?
$arr=array('a'=>'á');
echo json_encode($arr);
Run Code Online (Sandbox Code Playgroud)
mb_internal_encoding('UTF-8');并$arr=array_map('utf8_encode',$arr);没有解决它.
结果: {"a":"\u00e1"}
预期结果: {"a":"á"}
我想以跨浏览器的方式使用jQuery和AJAX实现导航历史记录.我的方法是使用window.history.pushState并回退到/#!/url不支持的浏览器中的哈希URL window.history.pushState.
例如:
<a href="/home">home</a>
<a href="/about">about</a>
<a href="/contact">contact</a>
Run Code Online (Sandbox Code Playgroud)
在支持的浏览器window.history.pushState,点击这些链接之一,应该没有刷新页面更改地址http://domain.com/home,http://domain.com/about等.当浏览器不支持window.history.pushState,就应该使用片段标识符,即:http://domain.com/#!/ home,http://domain.com/#!/about.
更新:根据这里的反馈,我实现了Ajax SEO(git),它使用
旧的浏览器回退的HTML5历史API的jQuery地址/#!/url.
如何启用-webkit-animation:before和:after伪元素?
您可以在http://jsfiddle.net/4rnsx/中看到它不适用于:before和:after.
在这里,我尝试使用Mootools http://jsfiddle.net/6bzCS/启用此功能.
Mozilla - 将在Firefox 4中支持它https://developer.mozilla.org/en/CSS/-moz-transition-property
W3C - CSS3支持所有元素的transition-property,:before和:after伪元素http:// www.w3.org/TR/css3-transitions/#transition-property
更新:如何启用fadein,fadeout对CSS3工具提示http://css-plus.com/2010/04/create-a-speech-bubble-tooltip-using -css3-and-jquery /和demo?
讨论开始jQuery:如何处理sortable('serialize')返回的列表?
如何从最后到第一个反转,updateList.php?id [] = 5&id [] = 4&id [] = 3&id [] = 2&id [] = 1 && action = update?
<ul>
<li id="oreder-5">5</li>
<li id="oreder-4">4</li>
<li id="oreder-3">3</li>
<li id="oreder-2">2</li>
<li id="oreder-1">1</li>
<ul>
Run Code Online (Sandbox Code Playgroud)
我的代码:
$(document).ready(function(){
order=[];
$('#list ul').children('li').each(function(idx, elm) { order.push(elm.id.split('-')[1]) });
$.post('updateList.php', {'order[]': order, action: 'update'});
function slideout(){
setTimeout(function(){ $("#response").slideUp("slow", function () {}); }, 2000);
}
$("#response").hide();
$(function() {
$("#list ul").sortable({ opacity: 0.8, cursor: 'move', update: function() {
var order = $(this).sortable("serialize") + '&action=update';
$.post("updateList.php", order, function(theResponse){
$("#response").html(theResponse); …Run Code Online (Sandbox Code Playgroud) javascript jquery serialization jquery-ui jquery-ui-sortable
jQuery的:如何启用timeout的$.ajax({dataType:'jsonp'...?有什么解决方案吗?http://jsfiddle.net/laukstein/2wcpU/4
$.ajax({
type:"GET",
url:'http://lab.laukstein.com/ajax-seo/.json',
dataType:'jsonp',
timeout:200, // Not working with dataType:'jsonp'
success:function(data){$('#content').html(data.content);},
error:function(request,status,error){$('#content').html('request failed');}
});
Run Code Online (Sandbox Code Playgroud)
我不喜欢使用一些插件,比如http://code.google.com/p/jquery-jsonp.
如何<option selected="selected">通过MySQL和PHP 进行设置?
我的代码:
echo '<select>';
$tempholder = array();
$rs = mysql_query("SELECT * FROM id ORDER BY year");
$nr = mysql_num_rows($rs);
for ($i=0; $i<$nr; $i++){
$r = mysql_fetch_array($rs);
//if($year==$r["year"]){ $selected=' selected="selected"'; }//doesn't work so
if (!in_array($r['year'], $tempholder)){
$tempholder[$i] = $r['year'];
echo "<option>".$r["year"]."</option>";//<option$selected>...
}
}
unset($tempholder);
echo '</select>';
Run Code Online (Sandbox Code Playgroud) 如何在 Firefox 上'\'用斜杠重写反斜杠?'/'
Chrome、IE、Safari、Opera 已构建浏览器用斜杠重写反斜杠。
但 Firefox 3.6.13 返回404 错误页面。
# Why Firefox returns 404 error page?
RewriteCond %{REQUEST_URI} (.*)\\(.*)
RewriteRule .* %1/%2 [R=301,L]
Run Code Online (Sandbox Code Playgroud) Firebug 1.5.4 JavaScript警告:不应使用事件的'charCode'属性keyup.价值毫无意义.忽略它?有什么问题吗?
该警告出现的jQuery 1.4.2 keyup和keydown,不是keypress.
我已阅读,在不断变化的event.keyCode,并event.charCode以event.which必须修复它,但它并没有为我工作.http://jsfiddle.net/zTevK/2/中的
完整代码示例和问题
我的代码使用和不兼容.keyupkeypress
$(document).bind('keyup', function(e){
var key = e.which;
if (key > 36 && key < 41) {
if (key == 37) { changeTab(-1); }
if (key == 38) { changeTab(-imgPerRow); }
if (key == 39) { changeTab(+1); }
if (key == 40) { changeTab(+imgPerRow); }
e.preventDefault();
...
Run Code Online (Sandbox Code Playgroud) jQuery的:如何启用beforeSend的$.ajax({dataType:'jsonp'...?有什么解决方案吗?
http://jsfiddle.net/laukstein/2wcpU/
<div id="content"></div>
<script>
$.ajax({
type:"GET",
url:'http://lab.laukstein.com/ajax-seo/.json',
dataType:'jsonp',
async:false,
beforeSend:function(data){ // Are not working with dataType:'jsonp'
$('#content').html('Loading...');
},
success:function(data){
$('#content').html(data.content);
}
});
</script>
Run Code Online (Sandbox Code Playgroud) 为什么 MySQL 返回# MySQL returned an empty result set (i.e. zero rows).和3 row(s) affected.?我的SQL语句有问题吗?
CREATE TABLE IF NOT EXISTS `test` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`order` mediumint(8) NOT NULL,
`url` varchar(70) COLLATE utf8_unicode_ci NOT NULL,
`title` varchar(70) COLLATE utf8_unicode_ci NOT NULL,
`content` text COLLATE utf8_unicode_ci,
PRIMARY KEY (`id`),
UNIQUE KEY `url` (`url`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
# MySQL returned an empty result set (i.e. zero rows).
INSERT INTO `test` (`id`, `order`, `url`, `title`, …Run Code Online (Sandbox Code Playgroud) 似乎在MySQL 5.5上SELECT DISTINCT工作正常只有一列.
SELECT DISTINCT type FROM table
WHERE type LIKE 'h%'
LIMIT 5;
Run Code Online (Sandbox Code Playgroud)
返回好结果:
type
--------
htm
html
htaccess
Run Code Online (Sandbox Code Playgroud)
但是在尝试SELECT两列或更多列时
SELECT DISTINCT id, type FROM table
WHERE type LIKE 'h%'
LIMIT 5;
Run Code Online (Sandbox Code Playgroud)
它返回重复查询失败的结果:
id | type
---+--------
1 | htm
3 | htm
5 | html
6 | html
7 | html
Run Code Online (Sandbox Code Playgroud)
预期结果:
id | type
---+--------
3 | htm
7 | html
5 | htaccess
Run Code Online (Sandbox Code Playgroud)
列id没有必要申请DISTINCT,因为它有AUTO_INCREMENT.
是否可以使用一个SQL查询实现?有什么改进?
$query = mysql_query("SELECT id, name FROM fruits WHERE `group`=''");
if ($query) {
while ($row = mysql_fetch_array($query, MYSQL_ASSOC)) {
echo $row['name'];
$query2 = mysql_query("SELECT name FROM fruits WHERE `group`='{$row['id']}'");
if (mysql_num_rows($query2)) {
echo ':';
while ($row2 = mysql_fetch_array($query2, MYSQL_ASSOC)) {
echo ' '. $row2['name'] . ',';
}
mysql_free_result($query2);
echo '<br>';
}
}
mysql_free_result($query);
}
Run Code Online (Sandbox Code Playgroud)
结果:
Berries: blueberry, raspberry, strawberry,
Citrus: grapefruit, lime,
Pear
Run Code Online (Sandbox Code Playgroud)
数据库结构SELECT * FROM fruits:
id | group | name
-------------------------
03E7 | | Berries
0618 …Run Code Online (Sandbox Code Playgroud)