0

i am trying to write my object to an xml file. but i get error in my Writexml function.

 function writexml(listXML) { $.ajax({ type: 'POST', url: "c:\\users\nagia\documents\visual studio2013\Projects\Webtrystuff\Webtrystuff\XMLFile1.xml", //path dataType: 'xml', data: { filename: "XMLFile1.xml", content: listXML }, error: function () { alert("Unknown error. Data could not be written to the file."); }, success: function () { window.open("XMLFile1.xml"); } }); } 

This is my function to call the writexml.

 <script> $(document).ready(function () { $("#datepicker").datepicker({ beforeShowDay: function(date) { var event = events[date]; writexml(event); if (event) { return [true, event.className, event.text, event.date]; } else { return [true, '', '']; } } }) }); </script> 

event is a my object in jquery.

 var Event = function (text, className) { this.text = text; this.className = className; }; 

I have to use ajax. Is there something wrong with sending the object like this? I am a beginner.

5
  • I also tried giving the path of my xml file like "~/XMLFile1.xml" ...still got the error case. Commented Apr 21, 2015 at 18:41
  • are you... trying to do a POST to an xml file? stackoverflow.com/a/12000090/526704 Commented Apr 21, 2015 at 18:45
  • yes post to a local xml file ... Commented Apr 21, 2015 at 19:05
  • 1
    that's not going to work. an XML file is not a web server. Commented Apr 21, 2015 at 19:06
  • well what can I do then ? my assingmnent question says that "function will make an Ajax call and save those events in a XML file" how can I save my "even"t object using ajax. Commented Apr 21, 2015 at 19:18

1 Answer 1

1

Are you using this code in a browser? In that case I'm not sure but i think that you could have a problem of cross domain call. In your code the url definition is incorrect because is the link of a resources in your filesystem with a absolute path:

url: "c:\\users\nagia\documents\visual studio2013\Projects\Webtrystuff\Webtrystuff\XMLFile1.xml" 

From your browser, for security reason you cannot call resources outside of your domain.

link for the wiki page about Crossdomain call

you can se more about this problem in this stackoverflow thread Using AJAX to read local files

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

3 Comments

I am writing to a local xml file. I am running the code in a webform.
Then it should work with the relative url "~/XMLFile1.xml" but why isnt then?
for cross domain problems I already have CORS extension installed in my browser so that cant be an issue

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.