I am using the code below which is fine but when I use the code below that in an attempt to send an html fragment to a processing page to save it as a file but I get nothing.
I have tried using ajax with processDat开发者_如何学运维a set to false ads dataTypes of html, text and xml but nothing works. I can't find anything on this so I guess I must be missing something fairly trivial but I've been at it for 3 hours now.
This works
$.post("SaveFile.aspx", {f: "test4.htm", c: "This is a test"},
function(data){
alert(data);
}, "text");
This fails
$.post("SaveFile.aspx", {f: "test4.htm", c: "<h1>This is a test</h1>"},
function(data){
alert(data);
}, "text");
Try uriEncoding the value first, like this...
It may get the xml to your endpoint as intended.
var value = encodeURIComponent("<h1>This is a test</h1>");
$.post("SaveFile.aspx", {f: "test4.htm", c:value },
function(data){
alert(data);
}, "text");
If theres an error on the server, .post success function will not get called. Try using .ajax and pass a success and error function.
It think you're error comes from the ValidateRequest in asp.net. You cannot send plain html to a asp.net page without htmlEncoding your html or disabling the ValidateResquest param on the @page directive of the aspx page or in the web.config if you want to do this for all your pages.
Wanna learn more about asp.net ? Visit http://www.developerit.com
精彩评论