简体   繁体   中英

ajax call for string method not working

I want to set a html content to TinyMCE editor content in ASP.NET MVC

so I come come with a solution that convert that HTML file to string in server side and then call it using ajax in client side

this is C# controller method

[HttpGet]
public string TyneMice()
{
    return System.IO.File.ReadAllText(@"C:\Users\..\myhtml.html");
}

this is ajax call ,

<script type="text/javascript">    

          tinymce.init({

            ...,

            setup: function (ed) {
                ed.on("init", function (ed) {

                    $.ajax({
                        type: "GET",
                        url: "Brochure/TyneMice",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {

                            tinyMCE.activeEditor.setContent(data);
                        },

                        error: function () { alert("Ajax Error"); }
                    });

                })
            }

        });

 </script>

But Once I put debug point on above string method it is not invoking

Then I put above script inside $( document ).ready(function() { ... }

But the same result it doesnt work.

Your Action should return of type ActionResult. The action will return Json object with JsonRequestBehavior set as AllowGet.

[HttpGet]
public JsonResult TyneMice()
{           
    return Json("TyneMice Example", JsonRequestBehavior.AllowGet);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM