views:

131

answers:

3

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 processData 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");  
+2  A: 

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");
Sky Sanders
A: 

If theres an error on the server, .post success function will not get called. Try using .ajax and pass a success and error function.

Yisroel
I doubt that there's an error on the server, because he's basically passing the same input to the same place each time, except he has some markup in the second one.
Maxim Zaslavsky
While I doubt it as well, its the only difference between the 2 snippets
Yisroel
A: 

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

Developer IT
NB: Disabling the validateRequest may be a security leak. So you better use htmlEnconding and use a whitelist to validate that nobody send script tags, since this could be a potential xss attack.
Developer IT