javascript asp.net MVC3 和 jquery AJAX 教程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6655466/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
asp.net MVC3 and jquery AJAX tutorial
提问by DotnetSparrow
I need a very detailed ebook/tutorial/video in very simple language for jquery AJAX and JSON with asp.net MVC3 . I have been googling but could't find any good one. Please send me links.
我需要一个非常详细的电子书/教程/视频,使用非常简单的语言,用于 jquery AJAX 和 JSON with asp.net MVC3 。我一直在谷歌搜索,但找不到任何好的。请把链接发给我。
Thanks.
谢谢。
回答by Andrew Orsich
From a client side use $.ajax:
从客户端使用$.ajax:
$.ajax({
type: "POST",
url: "users/save",
data: "name=John&location=Boston",
success: function(msg){
alert( "Data Saved: " + msg );
}
From a server side handle ajax requests:
从服务器端处理ajax请求:
public ActionResult Save(string name, string location)
{
//Save data
return new JsonResult(){Data = "User was saved!"};
}
Use JsonResultto return json string to the client and JSON.parseto parse json string at the client side.
使用JsonResult向客户端返回 json 字符串,使用JSON.parse在客户端解析 json 字符串。
To simplify ajax calls you can also create wrappers around $.ajax and JsonResult, define your ajax requests structure like {data:"jsonString", messagess: [], redirect_url }
etc.
为了简化 ajax 调用,您还可以围绕 $.ajax 和 JsonResult 创建包装器,定义您的 ajax 请求结构等{data:"jsonString", messagess: [], redirect_url }
。
That's all tutorial.
这就是全部教程。
回答by Feferes.net
回答by imdondo
You could try one of the sessions from the MVCConf presented by Eric Sowell (@Mallioch). It is a good tutorial and so are quite a number.
您可以尝试 Eric Sowell (@Mallioch) 提出的 MVCConf 中的一个会话。这是一个很好的教程,所以有很多。
回答by awrigley
Eric Sowell was mentioned above.
上面提到了埃里克·索威尔。
The link to his talk is:
他的演讲链接是:
Evolving Practices in Using jQuery and Ajax in ASP.NET MVC Applications
在 ASP.NET MVC 应用程序中使用 jQuery 和 Ajax 的演进实践
You need to understand JavaScript prototypes to understand, or rather, be able to use the recommended practice.
您需要了解 JavaScript 原型才能理解,或者更确切地说,能够使用推荐的做法。
But it is well worth it. You end up with a VERY reusable pattern for ALL the javascript in your apps, not just the AJAX bits.
但这是值得的。您最终会为您的应用程序中的所有 javascript 提供一个非常可重用的模式,而不仅仅是 AJAX 位。
Plus you have something to bang your head against until you really understand JavaScript, as opposed to Cookbook recipes for jQuery.
另外,在您真正理解 JavaScript 之前,您有一些需要注意的地方,而不是 jQuery 的 Cookbook 食谱。
Ie, if you don't structure your jQuery/JS in some way, you will end up with a bowl of spaghetti.
也就是说,如果你不以某种方式构建你的 jQuery/JS,你最终会得到一碗意大利面。
Other books: David Crockford wrote a short book: Javascript, the Good Parts. This explains prototypes and a lot else, very concisely. There is also a GREAT article in MSDN Magazine, May 2007 by Ray Djajadinata:
其他书籍:David Crockford 写了一本短书:Javascript, the Good Parts。这非常简洁地解释了原型和许多其他内容。2007 年 5 月,Ray Djajadinata 在 MSDN 杂志上也有一篇很棒的文章:
JavaScript: Create Advanced Web Applications with Object-Oriented Techniques
JavaScript:使用面向对象技术创建高级 Web 应用程序
If you read that article ten times, you will understand JavaScript.
如果你把那篇文章读十遍,你就会理解 JavaScript。
回答by dsmalls
Did you try the official Microsoft resources?