<?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>裁纸刀下 &#187; Ajax</title>
	<atom:link href="http://ofcss.com/tags/ajax/feed" rel="self" type="application/rss+xml" />
	<link>http://ofcss.com</link>
	<description>独立 自由 诚信 宽容 责任 平常心</description>
	<lastBuildDate>Thu, 19 Jan 2012 14:24:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>[翻译]ASP.NET MVC动手实验1-2：创建ASP.NET MVC应用</title>
		<link>http://ofcss.com/2009/04/09/aspnetmvc-hands-on-labs-create-application.html</link>
		<comments>http://ofcss.com/2009/04/09/aspnetmvc-hands-on-labs-create-application.html#comments</comments>
		<pubDate>Thu, 09 Apr 2009 15:08:09 +0000</pubDate>
		<dc:creator>小李刀刀</dc:creator>
				<category><![CDATA[所谓技术]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[动手实验]]></category>
		<category><![CDATA[翻译]]></category>

		<guid isPermaLink="false">http://wukangrui.net/2009/04/09/aspnetmvc-hands-on-labs-create-application.html</guid>
		<description><![CDATA[<p>在这个练习中你将学习如何在 Visual Studio 中创建一个 ASP.NET MVC 应用。并初步了解默认项目结构和一些开发约定。 ASP.NET MVC 框架分为 Model， View 和 Controller 三个部分。模型组件（Model）一般用于维护数据库中的持久数据层的状态。视图组件（View）由控制器挑选并渲染到适当的用户界面。默认状态下， ASP.NET MVC 框架用ASP.NET已有的 ASP.NET 页面（.aspx）、 母版页（.master）以及用户控件（.ascx）等类型来作为浏览器呈现。控制器组件（Controller）组件将用户请求定位到适当的控制器（Controller）行为（Action）和方法（Method），从请求中获取用于行为方法运行的参数值， 并处理行为和方法执行中可能产生的错误。 然后控制器用该请求对应的视图进行渲染。 默认状况下，每个组件存放在 MVC WEB 应用工程的一个独立目录下。 任务1 &#8211; 创建一个 ASP.NET MVC Web 应用工程 在这个任务中你将通过Visual Studio的MVC模板创建和配置一个空的 ASP.NET MVC 应用工程。 打开 &#8230; <a href="http://ofcss.com/2009/04/09/aspnetmvc-hands-on-labs-create-application.html">Continue reading <span class="meta-nav">&#8594;</span></a></p>
]]></description>
			<content:encoded><![CDATA[<p>在这个练习中你将学习如何在 Visual Studio 中创建一个 ASP.NET MVC 应用。并初步了解默认项目结构和一些开发约定。</p>
<p>ASP.NET MVC 框架分为 Model， View 和 Controller 三个部分。模型组件（Model）一般用于维护数据库中的持久数据层的状态。视图组件（View）由控制器挑选并渲染到适当的用户界面。默认状态下， ASP.NET MVC 框架用ASP.NET已有的 ASP.NET 页面（.aspx）、 母版页（.master）以及用户控件（.ascx）等类型来作为浏览器呈现。控制器组件（Controller）组件将用户请求定位到适当的控制器（Controller）行为（Action）和方法（Method），从请求中获取用于行为方法运行的参数值， 并处理行为和方法执行中可能产生的错误。 然后控制器用该请求对应的视图进行渲染。 默认状况下，每个组件存放在 MVC WEB 应用工程的一个独立目录下。</p>
<p><span id="more-444"></span></p>
<p><strong>任务1 - 创建一个 ASP.NET MVC Web 应用工程</strong></p>
<p>在这个任务中你将通过Visual Studio的MVC模板创建和配置一个空的 ASP.NET MVC 应用工程。</p>
<ol>
<li>打开 Microsoft Visual Studio 2008：依次点击 <strong>开始</strong>|<strong>所有程序</strong>|<strong>Microsoft Visual Studio 2008</strong>|<strong>Microsoft Visual Studio 2008</strong>.</li>
<li>点击 <strong>文件</strong> 菜单， 指向 <strong>新建</strong>， 然后点击 <strong>项目</strong>。</li>
<li>在 <strong>新建项目</strong> 对话框中，确保右上角选中的版本为 <strong>.NET Framework 3.5</strong>，在 <strong>项目类型</strong> 下选择 <strong>Visual C#</strong>，然后在 <strong>Visual Studio 已安装的模板</strong> 中选择 <strong>ASP.NET MVC Web Application</strong> 类型。你可以设置项目位置为 <strong>你的路径AspNetMvcEx01-CreatingMvcAppbegin </strong>作为项目目录。</li>
<li>修改 <strong>名称</strong> 为 <strong>MvcSampleApp</strong> 然后点击 确定 。 <a href="http://file.wukangrui.com/attachments/2009/04/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://file.wukangrui.com/attachments/2009/04/image-thumb.png" border="0" alt="image" width="605" height="484" /> </a><em>图一：创建新项目对话框<br />
</em>在点击 确定 按钮之后，Visual Studio 会问你是否同时创建测试项目（would you like to create a test project）。选择 <strong>Yes</strong>， 输入 <strong>MvcSampleApp.Test</strong> 作为<strong>项目名称</strong>（<strong>Name</strong> of the Project）， 然后点击 <strong>确定</strong>（<strong>OK</strong>）。注：我安装的是Visual Studio 2008 SP1 简体中文版 + ASP.NET MVC 1.0，在我的系统上，创建测试项目的对话框为英文，因此这里加上英文对照。<br />
提示：当你创建一个新的MVC Web应用时， Visual Studio 会为你提供同时创建两个项目的选择，第一个项目是Web项目用来实现你的应用，第二个项目是一个测试项目，你可以在其中为你的MVC组件编写单元测试。<br />
<a href="http://file.wukangrui.com/attachments/2009/04/image2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://file.wukangrui.com/attachments/2009/04/image-thumb2.png" border="0" alt="image" width="552" height="367" /></a><br />
<em>图二：创建 MVC 单元测试项目<br />
</em>提示：测试项目对话框中的 测试框架（Test Framework） 下拉列表现在只有一个 Visual Studio Unit Test，这个列表是可扩展的，在你的机器上安装了其他测试框架的时候，它将会包含其他的测试框架供你选择。由此你可以容易地用你喜欢的单元测试框架来为你的 ASP.NET MVC 应用编写单元测试。</li>
<li>在Visual Studio 中配置站点使用端口 50000。这一步是为了和本动手实验中的后续联系保持一致所必须的。
<ol type="a">
<li>在 <strong>解决方案浏览器</strong> 中，右击 <strong>MvcSampleApp</strong> 项目，并在上下文菜单中选择 <strong>属性</strong> 。</li>
<li>在 <strong>属性</strong> 页中，打开 <strong>Web</strong> 标签。</li>
<li>In the <strong>Servers</strong> section select <strong>Specific Port</strong>. 在 <strong>服务器</strong> 设置项下面，选择 <strong>使用Visual Studio开发服务器</strong>，并选中 <strong>特定端口</strong> 。</li>
<li>设置端口号为 <strong>50000</strong> 。</li>
<li>按下 <strong>Ctr + S</strong> 保存所做的改动。</li>
</ol>
<p><a href="http://file.wukangrui.com/attachments/2009/04/image3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://file.wukangrui.com/attachments/2009/04/image-thumb3.png" border="0" alt="image" width="635" height="480" /></a><br />
<em>图三：配置本地测试属性</em></li>
</ol>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>2009-04-13 -- <a href="http://ofcss.com/2009/04/13/aspnetmvc-hands-on-labs-develop-application.html" title="[翻译]ASP.NET MVC动手实验1-3：开发ASP.NET MVC应用">[翻译]ASP.NET MVC动手实验1-3：开发ASP.NET MVC应用</a></li><li>2009-04-09 -- <a href="http://ofcss.com/2009/04/09/aspnetmvc-hands-on-labs-introduction.html" title="[翻译]ASP.NET MVC动手系列1-1：ASP.NET MVC概述">[翻译]ASP.NET MVC动手系列1-1：ASP.NET MVC概述</a></li><li>2009-07-08 -- <a href="http://ofcss.com/2009/07/08/asp-net-mvc-best-practices-part-4.html" title="ASP.NET MVC 最佳实践（四）">ASP.NET MVC 最佳实践（四）</a></li><li>2009-07-07 -- <a href="http://ofcss.com/2009/07/07/asp-net-mvc-best-practices-part-3.html" title="ASP.NET MVC 最佳实践（三）">ASP.NET MVC 最佳实践（三）</a></li><li>2009-07-01 -- <a href="http://ofcss.com/2009/07/01/asp-net-mvc-best-practices-part-2.html" title="ASP.NET MVC 最佳实践（二）">ASP.NET MVC 最佳实践（二）</a></li><li>2009-06-28 -- <a href="http://ofcss.com/2009/06/28/asp-net-mvc-best-practices-part-1.html" title="ASP.NET MVC 最佳实践（一）">ASP.NET MVC 最佳实践（一）</a></li><li>2011-03-14 -- <a href="http://ofcss.com/2011/03/14/browser-rendering-optimizer-translation-extra.html" title="对《优化浏览器渲染》的补充【译】">对《优化浏览器渲染》的补充【译】</a></li><li>2009-06-22 -- <a href="http://ofcss.com/2009/06/22/whatever-hover-pseudo-class-without-javascript.html" title="Whatever:hover &#8211; 无需javascript让IE支持丰富伪类">Whatever:hover &#8211; 无需javascript让IE支持丰富伪类</a></li><li>2009-04-30 -- <a href="http://ofcss.com/2009/04/30/solution-for-js-intellisense-error.html" title="VS2008 中 JS IntelliSense出错的解决">VS2008 中 JS IntelliSense出错的解决</a></li><li>2011-03-10 -- <a href="http://ofcss.com/2011/03/10/css-border-tricks-with-collapsed-boxes-translation.html" title="CSS边框实现&ldquo;无图化&rdquo;设计【译】">CSS边框实现&ldquo;无图化&rdquo;设计【译】</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://ofcss.com/2009/04/09/aspnetmvc-hands-on-labs-create-application.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用JavaScript动态输出的JS脚本不能执行</title>
		<link>http://ofcss.com/2006/04/12/innerhtml-can-not-be-excuted.html</link>
		<comments>http://ofcss.com/2006/04/12/innerhtml-can-not-be-excuted.html#comments</comments>
		<pubDate>Wed, 12 Apr 2006 06:29:00 +0000</pubDate>
		<dc:creator>小李刀刀</dc:creator>
				<category><![CDATA[乱七八糟]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[动易]]></category>
		<category><![CDATA[开发]]></category>

		<guid isPermaLink="false">http://wukangrui.net/?p=133</guid>
		<description><![CDATA[<p>　　随着Ajax的越来越多地运用，HTML的内容又开始由“所见即所得”开始向“所见未必所得”发展了。这就是动态改变网页内容的魅力所在吧。 　　在公司产品动易2006版整合接口的开发过程中，需要在客户端页面上输出一段调用远程接口写cookies的代码，最早的时候我是把调用url通过script的方式输出。在ASP输出HTML的时候，调试通过。 　　动易2006的前台登陆表单已经采用了Ajax技术，页面上所看到的登陆表单并非直接由HTML代码在页面中写成，而是在页面加载以后，通过JS，通过Ajax，向服务器端的asp程序查询用户登录状态以后，再动态输出到页面的。 　　一开始我通过JS，动态生成调用script的HTML代码以后，输出到页面，跟其它的HTML代码一样。结果出现了通行登陆不能同步的问题。用alert调试发现代码已经正确生成，显然用innerHTML输出到页面以后，是没有问题的。但是为什么没有登陆呢？ 　　为这个问题，折磨了我一晚上。天亮的时候跟动网公司的迷城浪子聊到这个问题，老迷没看我的脚本，只是听我讲了一遍，回答我说“JS输出的JS脚本不能被执行的吧？” 　　难道真是这个问题？我把通过script调用改成通过img调用，还把图片大小设置成100*100，果然在页面上显示了，同步登陆也成功了。 　　后来我写了一个段测试脚本，果然是js输出的js将不能执行。具体看下面的代码： 　　在上面的例子中，可以看到页面执行了远程的js脚本，输出统计图标 　　把代码修改如下： &#60;!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&#62; &#60;html xmlns=”http://www.w3.org/1999/xhtml”&#62; &#60;head&#62; &#60;meta http-equiv=”Content-Type” content=”text/html; charset=gb2312&#8243; /&#62; &#60;title&#62;无标题文档&#60;/title&#62; &#60;/head&#62; &#60;body&#62; &#60;div id=”div”&#62;加载中&#8230;&#60;/div&#62; &#60;script type=”text/javascript” language=”javascript”&#62; var newStr = “&#60;script src=\”http://s33.cnzz.com/stat.php?id=109006&#38;web_id=108995&#38;show=pic\” language=\”JavaScript\” charset=\”gb2312\”&#62;&#60;\/script&#62;”; &#8230; <a href="http://ofcss.com/2006/04/12/innerhtml-can-not-be-excuted.html">Continue reading <span class="meta-nav">&#8594;</span></a></p>
]]></description>
			<content:encoded><![CDATA[<p>　　随着Ajax的越来越多地运用，HTML的内容又开始由“所见即所得”开始向“所见未必所得”发展了。这就是动态改变网页内容的魅力所在吧。</p>
<p>　　在公司产品动易2006版整合接口的开发过程中，需要在客户端页面上输出一段调用远程接口写cookies的代码，最早的时候我是把调用url通过script的方式输出。在ASP输出HTML的时候，调试通过。</p>
<p><span id="more-133"></span></p>
<p>　　动易2006的前台登陆表单已经采用了Ajax技术，页面上所看到的登陆表单并非直接由HTML代码在页面中写成，而是在页面加载以后，通过JS，通过Ajax，向服务器端的asp程序查询用户登录状态以后，再动态输出到页面的。</p>
<p>　　一开始我通过JS，动态生成调用script的HTML代码以后，输出到页面，跟其它的HTML代码一样。结果出现了通行登陆不能同步的问题。用alert调试发现代码已经正确生成，显然用innerHTML输出到页面以后，是没有问题的。但是为什么没有登陆呢？</p>
<p>　　为这个问题，折磨了我一晚上。天亮的时候跟动网公司的迷城浪子聊到这个问题，老迷没看我的脚本，只是听我讲了一遍，回答我说“JS输出的JS脚本不能被执行的吧？”</p>
<p>　　难道真是这个问题？我把通过script调用改成通过img调用，还把图片大小设置成100*100，果然在页面上显示了，同步登陆也成功了。</p>
<p>　　后来我写了一个段测试脚本，果然是js输出的js将不能执行。具体看下面的代码：</p>
<pre lang="html"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

</head>
<body>
<div id="div">
    <script type="text/javascript" language="javascript">
        document.write("<script src=\"http://s33.cnzz.com/stat.php?id=109006&#038;web_id=108995&#038;show=pic\" language=\"JavaScript\" charset=\"gb2312\"><\/script>");
    </div>

</script>
</body>
</html></pre>
<p>　　在上面的例子中，可以看到页面执行了远程的js脚本，输出统计图标<br />
　　把代码修改如下：</p>
<blockquote><p>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;<br />
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;<br />
&lt;head&gt;<br />
&lt;meta http-equiv="Content-Type" content="text/html; charset=gb2312" /&gt;<br />
&lt;title&gt;无标题文档&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
    &lt;div id="div"&gt;加载中...&lt;/div&gt;<br />
    &lt;script type="text/javascript" language="javascript"&gt;<br />
        var newStr = "&lt;script src=\"http://s33.cnzz.com/stat.php?id=109006&amp;web_id=108995&amp;show=pic\" language=\"JavaScript\" charset=\"gb2312\"&gt;&lt;\/script&gt;";<br />
        document.getElementById("div").innerHTML = newStr;<br />
    &lt;/script&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p></blockquote>
<p>　　可以看到“加载中...”字样已经被下面的JS代码动态输出的代码替换了，但是并没有显示统计图标，说明script脚本调用代码已经被输出到页面，但是没有被执行。</p>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>2008-06-22 -- <a href="http://ofcss.com/2008/06/22/api-bug-in-powereasy-siteweaver-part2.html" title="动易SW中的一个严重但不影响使用的bug（二）">动易SW中的一个严重但不影响使用的bug（二）</a></li><li>2008-06-22 -- <a href="http://ofcss.com/2008/06/22/thinking-about-html-page-creating.html" title="静态页面生成的思考">静态页面生成的思考</a></li><li>2008-06-18 -- <a href="http://ofcss.com/2008/06/18/api-bug-in-powereasy-siteweaver-part1.html" title="动易SW中的一个严重但不影响使用的bug(一)">动易SW中的一个严重但不影响使用的bug(一)</a></li><li>2008-05-23 -- <a href="http://ofcss.com/2008/05/23/disadvantages-of-discuz-ucenter.html" title="给UCenter的拥蹩们泼点冷水">给UCenter的拥蹩们泼点冷水</a></li><li>2007-01-30 -- <a href="http://ofcss.com/2007/01/30/new-thinking-about-application-intergration.html" title="整合开发的新思路">整合开发的新思路</a></li><li>2009-07-08 -- <a href="http://ofcss.com/2009/07/08/asp-net-mvc-best-practices-part-4.html" title="ASP.NET MVC 最佳实践（四）">ASP.NET MVC 最佳实践（四）</a></li><li>2009-07-07 -- <a href="http://ofcss.com/2009/07/07/asp-net-mvc-best-practices-part-3.html" title="ASP.NET MVC 最佳实践（三）">ASP.NET MVC 最佳实践（三）</a></li><li>2009-07-05 -- <a href="http://ofcss.com/2009/07/05/php-5-3-0-release-new-feature.html" title="PHP 5.3.0 发布">PHP 5.3.0 发布</a></li><li>2009-07-01 -- <a href="http://ofcss.com/2009/07/01/asp-net-mvc-best-practices-part-2.html" title="ASP.NET MVC 最佳实践（二）">ASP.NET MVC 最佳实践（二）</a></li><li>2009-06-28 -- <a href="http://ofcss.com/2009/06/28/asp-net-mvc-best-practices-part-1.html" title="ASP.NET MVC 最佳实践（一）">ASP.NET MVC 最佳实践（一）</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://ofcss.com/2006/04/12/innerhtml-can-not-be-excuted.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

