2

what i am doing is:

  1. reading a xml file with ajax get method

  2. and then updating a particular node value of xml

  3. after updating this xml response i am posting it to the server side (php) for writing that xml file again

i am getting error in posting the updated xml response to server side the error is: NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument

i found this accepted answer but this didn't work for me: How to change the value of an xml node with jquery?

here is my somecode:

$.ajax({
                url: "<?php echo $xmlFilePath;?>",
                type: "GET",
                dataType: "xml",
                success: function(xml){    

                    $(xml).find("Page[id='1']").each(function(){
                       $(this).find('ContentOne').text("New Value");
                    });

                 $.post('<?php echo base_url(); ?>contentadd', { xml: escape($(xml))}, function(data){alert("Data Loaded: " + data);});

                }
        });

any quick response will be helpfull

Community
  • 1
  • 1
sandeepKumar
  • 771
  • 2
  • 12
  • 33
  • Which part of the error message `NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument` is hard for you to grasp? – hakre Aug 10 '12 at 13:07
  • @hakra actually i am sending xml response and it need to be escaped...i did that but still i didn't able to decode it in php script – sandeepKumar Aug 10 '12 at 13:11
  • You get an error message. So you do something *wrong*. You need to find out *what*. The error message helps you to locate the problem, but it looks like there is some missing part for you to just solve it. Can you explain which part you do not understand about the error? That part will help you to find the location where the error is created. – hakre Aug 10 '12 at 13:13
  • @hakra as i said that xml response was creating problem but by putting escape function it is loading now that error don't occur but ...the in php script i need to decode it and it's not doing that..... – sandeepKumar Aug 10 '12 at 13:16
  • You have not posted any PHP code here. – hakre Aug 10 '12 at 13:17
  • @hakra that is only a single line $xml = ($this->input->post('xml')); i want to know how to decode that again ..which i have escaped xml content in jquery post method – sandeepKumar Aug 10 '12 at 13:23
  • @hakra can you tell me how to post the xml to sever side with jquery...after editing the xml node...or if u can share some link for me...i will be thankful to you – sandeepKumar Aug 10 '12 at 13:26
  • Did you try just `$.post('contentadd', $(xml), function(data){alert("Data Loaded: " + data);});`? – kernel Aug 14 '12 at 09:44
  • `escape($(xml))` won't give you anything useful, btw.. (see the example: http://jsfiddle.net/naRqS/) – apfelbox Aug 16 '12 at 09:36
  • See here: http://stackoverflow.com/questions/6507293/convert-xml-to-string-with-jquery – apfelbox Aug 16 '12 at 13:15

1 Answers1

0

Instead of escape I would try to serialize xml with jQuery and unserialize it on server side...

Greg Motyl
  • 2,478
  • 17
  • 31