0

I am trying to figure out why my Ajax query is not being sent to the controller when trying to send HTML data.

Using this simple POST to send the data:

        var contentFull = $("#contract").html();

        var url2 = '@Url.Action("SavePDF", "FRP")';
        $.ajax({
            url: url2,
            type: 'POST',
            contenttype: 'text/plain',
            async: true,
            data: {
                Content: contentFull
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                CustomAlert.render(XMLHttpRequest);
                CustomAlert.render(textStatus);
                CustomAlert.render(errorThrown);
                CustomAlert.render("Error while posting SendResult");
            },
            success: function (result) {
                CustomAlert.render("Yey?");
            }

        });

When changing contentFull to a simple string ("test"); the function SavePDF will activate and the content will be filled correctly. When using the POST as is; the succes function will fire off, but the SavePDF function is completely ignored.

I've been looking like crazy figuring out what the reason could be. First thought was the character limit issue which should be solved by using POST.

10
  • 1
    Open your browser console. I'm pretty sure there will be errors there. Commented May 25, 2016 at 8:06
  • Have been checking; no output while running the ajax post EDIT: I have been testing with IE 11 though, will test on Chrome Commented May 25, 2016 at 8:07
  • Possible duplicate of jQuery send HTML data through POST Commented May 25, 2016 at 8:08
  • Maybe your PHP script only accepts GET requests? Commented May 25, 2016 at 8:09
  • This might be helpful: Post HTML tag (codes) as string with ASP.net MVC & JQuery Commented May 25, 2016 at 8:09

3 Answers 3

2

Answer found below! https://www.owasp.org/index.php/ASP.NET_Request_Validation

Asp.net request validation ignored my request because of security XSS issues. By using the tag [ValidateInput(false)] in my MVC Controller; the function works as expected!

Sign up to request clarification or add additional context in comments.

Comments

1

Since i still can't comment, i'll use answering function instead. I don't think you need to specify contenttype and async, async is true by default, contenttype text/plain will not allow you to send html content.

var contentFull = $("#contract").html();

        var url2 = '@Url.Action("SavePDF", "FRP")';
        $.ajax({
            url: url2,
            type: 'POST',
            data: {
                Content: contentFull
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                CustomAlert.render(XMLHttpRequest);
                CustomAlert.render(textStatus);
                CustomAlert.render(errorThrown);
                CustomAlert.render("Error while posting SendResult");
            },
            success: function (result) {
                CustomAlert.render("Yey?");
            }

        });

7 Comments

Same error as I have been having before.. Sending normal text in contentFull works perfectly; having a bunch of HTML in there (in string format), doesn't
what framework you use? some framework will filter XSS when user post string. so please check your framework that does it be filtered. Sometimes there are some WAF will filter XSS as well.
I have updated my comment at above.you should turn xss protection off and try. owasp.org/index.php/ASP.NET_Request_Validation
@user2352577L THIS!! gives me a lot of hope! Thank you, I will check this out!
DING DING DING!! Correct answer!! Thank you so much @user2352577L
|
0
var contentFull = $("#contract").html();
var url2 = '@Url.Action("SavePDF", "FRP")';

$.ajax({
    url: url2,
    type: 'POST',
    async: true,
    data: {
        Content: contentFull
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
        CustomAlert.render(XMLHttpRequest);
        CustomAlert.render(textStatus);
        CustomAlert.render(errorThrown);
        CustomAlert.render("Error while posting SendResult");
    },
    success: function (result) {
        CustomAlert.render("Yey?");
    }
});  

2 Comments

This will work fine. you were added contenttype: 'text/plain', so it will accepts on only text.
Will try this now; As far as I remember; this is the function I originally started from EDIT: Same problem here; changing Content: "Test" works perfectly; having contentFull there does not fire SavePDF in the controller

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.