2009年8月20日星期四

ASP.NET MVC - Some Frequently Asked Questions

這個國外網站".NET咖哩"有很多不錯的文章,與Code-Project和DZone相當。

ASP.NET MVC - Some Frequently Asked Questions
This article introduces ASP.NET MVC and answers some frequently asked questions about ASP.NET WebForms vs ASP.NET MVC.
http://www.dotnetcurry.com/ShowArticle.aspx?ID=370

2009年8月9日星期日

Portable Aptana Studio

Aptana Studio是一個十分好用的IDE,而且PHP Plug-in 比 Eclipse PDT還要好。即使大公司Sun上個月推出的NetBeans 6.7都不及Aptana,我始終還是用不慣Netbeans的介面,而且對HTML / Javascript /CSS的支援實在太弱,所以我寫PHP一直都用Aptana。對於支援HTML / Javascript /CSS方面,如Code Completion / Hints,Aptana甚至做得比Visual Studio 2008更好。

20090808_aptana-t.jpg

Aptana官方網站雖然有Zip版本Download,不過並不是Portable。
但只需要幾步就可以打造自己的Portable版本了,步驟如下:

jQuery - Why Ajax return blank data?

jQuery的Ajax很好用,幾乎我已經以jQuery取代Microsoft的Ajax,但使用jQuery的Ajax Call Back要注意 Asynchronous (同步或非同步) 問題。
以這個典型例子:
$("InputButton").click(function () { 
$.ajax({
type: "POST",
url: "webservice/DataService.asmx/GetAccount",
data: "{AccountNo: '123' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg){ alert(msg); }
});
});

上面的例子是沒有問題的,但如果把Ajax部份寫成Function,就會出現CallBack空白的Data:
$("InputButton").click(function () { 
alert(GetAccountName('123'));
});

function GetAccountName(Code)
{
var r = '';
$.ajax({
type: "POST",
url: "webservice/DataService.asmx/GetAccount",
data: "{AccountNo: '" + Code +"' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
//async: false, //假設沒有這行
success: function(msg){
if (msg.length > 0) { r = msg; }
}
});
return r;
}

解決的方法就是加入這一行
async: false,

用意是需要等待jQuery 取得Data後才運行下一個動作。