0

I'd like to update html data through an xml put request. So what I've done is make an ajax request with the data

$.ajax({
  type: "PUT",
  url: "/network_internet_control_layouts/1.xml",
  data: '<network-internet-control-layout><layout>'+$("div#temp").html()+'</layout></network-internet-control-layout>',
  contentType: 'application/xml', 
  dataType: 'xml', 
  success: function(msg) {
    alert( "Data Saved: " + msg );
  }
});

When I look at my console, I see that the html code is escaped

Processing by NetworkInternetControlLayoutsController#update as XML
Parameters: {"network_internet_control_layout"=>{"layout"=>{"div"=>{"class"=>"tables", "div"=>{"style"=>"position: relative;", "class"=>"table", "div"=>{"class"=>"tablePart simple", "div"=>{"class"=>"block", "network_infrastructure_id"=>"1", "network_infrastructure_name"=>"VISI-201-NW"}}}}}}, "id"=>"1"}

And when it gets saved, it is totally wrong

AREL (0.5ms)  UPDATE `network_internet_control_layouts` SET `layout` = '--- !map:ActiveSupport::HashWithIndifferentAccess \ndiv: !map:ActiveSupport::HashWithIndifferentAccess \n class: tables\n div: !map:ActiveSupport::HashWithIndifferentAccess \n style: \"position: relative;\"\n class: table\n div: !map:ActiveSupport::HashWithIndifferentAccess \n class: tablePart simple\n div: !map:ActiveSupport::HashWithIndifferentAccess \n class: block\n network_infrastructure_id: \"1\"\n network_infrastructure_name: VISI-201-NW\n', `updated_at` = '2011-05-05 11:29:33' WHERE `network_internet_control_layouts`.`id` = 1

Is there a way to insert the raw data in the db?

Thanks

2 Answers2

0

Checkout this SO question where the jquery is using CDATA for the HTML inside of XML

Try :

data: '<network-internet-control-layout><layout><![CDATA[' + $("div#temp").html() + ']]</layout></network-internet-control-layout>'
Community
  • 1
  • 1
Jesse Wolgamott
  • 40,197
  • 4
  • 83
  • 109
  • Hi Jesse, I did try out your code, but now I'm getting a Declarations can only occur in the doctype declaration. Line: 3 Position: 318 Last 80 unconsumed characters: <![CDATA[
    – Reyntjensw May 09 '11 at 06:35
  • The solution was encrypting the html and decrypting it while getting it out of the database. – Reyntjensw May 30 '11 at 09:52
0

From rails3, by default it html codes will not be embeded. How ever if you still want to embed html you have to use

raw

ex:

html_code = "<table><tr><td>This is a Sample</td></tr></table>

<%= raw html_code%>

will print a html table

HTH

sameera

sameera207
  • 16,547
  • 19
  • 87
  • 152
  • Hi sameera, The problem I think are the quotes that are used, if there is a class or id, the problems start. I already tried replacing them with other characters but this was no success. – Reyntjensw May 10 '11 at 07:08