<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Erick &#187; 回调函数</title>
	<atom:link href="http://blog.xiongchuan.org/tag/callback-function/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.xiongchuan.org</link>
	<description>Even a great life is only a life until you make it.</description>
	<lastBuildDate>Thu, 10 Mar 2011 14:44:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
	
<!-- Start Of Script Generated By WP-PostViews Plus -->
<script type='text/javascript' src='http://blog.xiongchuan.org/wp-includes/js/jquery/jquery.js?ver=1.4.4'></script>
<script type="text/javascript">
/* <![CDATA[ */
/* ]]> */
</script>
<!-- End Of Script Generated By WP-PostViews Plus -->
	<item>
		<title>jQuery,callback&#124;回调函数的问题</title>
		<link>http://blog.xiongchuan.org/jquery-callback-function-something.html</link>
		<comments>http://blog.xiongchuan.org/jquery-callback-function-something.html#comments</comments>
		<pubDate>Wed, 07 Oct 2009 06:44:29 +0000</pubDate>
		<dc:creator>Erick</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[回调函数]]></category>

		<guid isPermaLink="false">http://www.pigblog.net/?p=307</guid>
		<description><![CDATA[用jquery一直都是用的异步传输，习惯了，今天在做表单提交验证一个字段的惟一性的时候，同样是用了异步，问题就出现了。 var checkwap=function(){ var total; $.ajax({ url:'bsmajax.php?type=checkwap', type:'GET', async:false,//原来是true, cache:false, data :{wapnum:$('input[id=wapnum]').val()}, dataType :'json', success :function(json){ total=json.total; } }); return total; }; alert(checkwap());//开始的时候怎么也得不到值，以为是jquery关于变量作用域的访问问题 多加了几个alert();后才觉悟，因为是异步的，alert(checkwap());先执行了，等ajax成功返回数据后total才有值。 因为在表单提交的验证是要实时的，所以就 async:false 了，变成同步的。 当我以为是变量作用域问题时，在GOOGLE里搜索时，也有人犯这样的迷糊，现在记下来。 Related Postsjavascript学习AJAX五步走,POST方法学习手记]]></description>
			<content:encoded><![CDATA[<p>用jquery一直都是用的异步传输，习惯了，今天在做表单提交验证一个字段的惟一性的时候，同样是用了异步，问题就出现了。</p>
<pre name="code" class="javascript">
	var checkwap=function(){
		var total;
		$.ajax({
			url:'bsmajax.php?type=checkwap',
			type:'GET',
			async:false,//原来是true,
			cache:false,
			data :{wapnum:$('input[id=wapnum]').val()},
			dataType :'json',
			success :function(json){
				total=json.total;
			}
		});
		return total;
	};
alert(checkwap());//开始的时候怎么也得不到值，以为是jquery关于变量作用域的访问问题
</pre>
<p>多加了几个alert();后才觉悟，因为是异步的，alert(checkwap());先执行了，等ajax成功返回数据后total才有值。<br />
因为在表单提交的验证是要实时的，所以就 async:false 了，变成同步的。</p>
<p>当我以为是变量作用域问题时，在GOOGLE里搜索时，也有人犯这样的迷糊，现在记下来。</p>
<h4  class="entry-title">Related Posts</h4><ul class="related_post"><li><a href="http://blog.xiongchuan.org/javascript-study.html" title="javascript学习">javascript学习</a></li><li><a href="http://blog.xiongchuan.org/to-study-ajax-follow-me.html" title="AJAX五步走,POST方法学习手记">AJAX五步走,POST方法学习手记</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.xiongchuan.org/jquery-callback-function-something.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

