跨域相关的文章老早写过几篇:
jquery url检测遇到的jquery跨域问题及JSONP的使用
本文是对第一篇的实例补充。
js脚本
$.getJSON ('http://sjolzy.cn/?callback=? &a=1&b=2', function(data) {
if (typeof(data) == 'object') {
$.each(data,function(i,j){
// ...
});
}
});
服务端代码
跨域相关的文章老早写过几篇:
jquery url检测遇到的jquery跨域问题及JSONP的使用
本文是对第一篇的实例补充。
js脚本
$.getJSON ('http://sjolzy.cn/?callback=? &a=1&b=2', function(data) {
if (typeof(data) == 'object') {
$.each(data,function(i,j){
// ...
});
}
});
服务端代码
先提下关于jQuery的$.Ajax 的async的作用,
官方的解释是
async Boolean Default: true
By default, all requests are sent asynchronous (e.g. this is set to true by default). If you need synchronous requests, set this option to false. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active.
async默认是true, 即为异步方式, $.Ajax执行后, 会继续执行ajax后面的脚步, 直到服务器端返回数据后, 触发$.Ajax里的success方法. 这时候执行的是两个线程.
我的出现闪屏的情况是:
$.ajax({
type: "post",
url: "index.php",
data: { },
async:false,
jQuery使用得比较顺手也比较喜欢,不得已也要用Prototype,小小整理下区别。。
// JQuery
// JQuery Shorthand
// Prototype
Wordpress博客后台登录输入错误的话登录窗口有左右抖动的效果。弄成jQuery函数方便调用(前提已载入jQuery包)
function shake(o){
var $panel = $("#"+o);
box_left = ($(window).width() - $panel.width()) / 2;
$panel.css({'left': box_left,'position':'absolute'});
for(var i=1; 4>=i; i++){
$panel.animate({left:box_left-(40-10*i)},50);
源码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>jQuery 3D文字</title>
<style type="text/css">
body{
font-family: Arial, "MS Trebuchet", sans-serif;
background-color: #111;
}
#list{
margin:0 auto;
height:600px;