$.ajax({
                    url: annotation_catalog_url,
                    type: ‘POST’,
                    dataType: ‘json’,
                    data: JSON.stringify(comment),
                    contentType: ‘application/json; charset=utf-8’,
                    success: function (data) {
                        if (data != null)
                            $(‘#result’).html(data.Message);
                    }
                });
            }
        }

        function save_handler() {
            if (tinyMCE.get(‘note_editor’)) {
                var html = tinyMCE.get(‘note_editor’).getContent();
                var comment = {
                        Id: -1,
                        User: ”,
                        PageUrl: ” + window.location.href,
                        Content: html
                };

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns=”http://www.w3.org/1999/xhtml” >
<head>
    <title>Tools</title>
    <link href=”http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css” rel=”stylesheet” type=”text/css”/>
    <LINK rel=”stylesheet” href=”http://jqueryui.com/demos/demos.css” />
    <script type=”text/javascript” src=”Scripts/jquery-1.4.2.min.js”></script>
    <script type=”text/javascript” src=”Scripts/jquery-ui-1.8.6.custom.min.js”></script>
    <script type=”text/javascript” src=”Scripts/tinymce/tiny_mce.js”></script>
    <script type=”text/javascript” src=”Scripts/tinymce/jquery.tinymce.js”></script>
</script>
    <script language=”javascript” type=”text/javascript”>
        var editor_selector = “#note_editor”;
        var annotation_catalog_url = ‘/Comment/Save’;

但只要您想透过Ajax向远程服务器传递数据呢?当然jQuery.Ajax里面有1个参数data参数允许你传递发送到服务器的数据。
但难题是,这些数额暗中认可是使用GET方式,即附加在央浼字符串(U大切诺基L QueryString)后边实现的,也正是说你见面临U帕杰罗L最大无法跨越4KB的限制。而只要您尝试用POST方法向ASP.NET MVC控制器发送数据的时候,在控制器一端,你会发现数目尚未传来到控制器上。比如说上面包车型客车jQuery代码:

点击提交后,在控制器1端根本未曾被调用,那是因为尽管你的jQuery代码指明了数据类型是json,可是多少格式并不是json格式的。你需求将指标种类化成json格式,使用json二.js就能够做这么些业务,下载地址是:http://www.json.org/js.html

   <div id=”result”>
   </div>
</body>

 

                $.ajax({
                    url: annotation_catalog_url,
                    type: ‘POST’,
                    dataType: ‘json’,
                    data: comment,
                    contentType: ‘application/json; charset=utf-8’,
                    success: function (data) {
                        if (data != null)
                            $(‘#result’).html(data.Message);
                    }
                });
            }
        }

        $(document).ready(function () {
            $(‘#submit’).click(save_handler);            
        });
    </script>
</head>
<body>
   <div id=”note_editor”>
   </div>
   <input type=”button” value=”提交” id=”submit” />   

ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());

 

   <div id=”result”>
   </div>
</body>

        function save_handler() {
            if (tinyMCE.get(‘note_editor’)) {
                var html = tinyMCE.get(‘note_editor’).getContent();
                var comment = {
                        Id: -1,
                        User: ”,
                        PageUrl: ” + window.location.href,
                        Content: html
                };

        function show_annotation_dialog() {
            $(editor_selector).tinymce({
                mode: “textareas”,
                theme: “simple”
            });
        }

json 1json 2代码

        $(document).ready(function () {
            $(‘#submit’).click(save_handler);            
        });
    </script>
</head>
<body>
   <div id=”note_editor”>
   </div>
   <input type=”button” value=”提交” id=”submit” />   

jQuery自带了Ajax的函数,你能够使用它从远程服务器下载网页,但难题是,超过四分之二Ajax皆以透过GET那种办法与长途服务器交互的。

json 3json 4代码

在ASP.NET MVC 叁 中华VC今后的本子就不必要加上那1行代码了。

        function show_json,annotation_dialog() {
            $(editor_selector).tinymce({
                mode: “textareas”,
                theme: “simple”
            });
        }

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns=”http://www.w3.org/1999/xhtml” >
<head>
    <title>Tools</title>
    <link href=”http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css” rel=”stylesheet” type=”text/css”/>
    <LINK rel=”stylesheet” href=”http://jqueryui.com/demos/demos.css” />
    <script type=”text/javascript” src=”Scripts/jquery-1.4.2.min.js”></script>
    <script type=”text/javascript” src=”Scripts/jquery-ui-1.8.6.custom.min.js”></script>
    <script type=”text/javascript” src=”Scripts/tinymce/tiny_mce.js”></script>
    <script type=”text/javascript” src=”Scripts/tinymce/jquery.tinymce.js”>
    <script type=”text/javascript” src=”Scripts/json2.js”></script>
</script>
</script>
    <script language=”javascript” type=”text/javascript”>
        var editor_selector = “#note_editor”;
        var annotation_catalog_url = ‘/Comment/Save’;

万1你在服务器的控制器一端,发生多少尚未被科学地反系列化(假使你用ASP.NET MVC 三 CR-VC以前的版本应该就会碰着这几个难点)。那是因为就算客户端指明了数额是json对象,然则,服务器MVC路由器不知晓怎么样诠释这么些指标,要在劳动器端加上json反连串化辅助,请在global.asax.cs的Application_Start()函数里,添加上边壹行代码(表示您要协理json反种类化):

相关文章

网站地图xml地图