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.

aneena
  • 187
  • 1
  • 2
  • 13
  • I also tried giving the path of my xml file like "~/XMLFile1.xml" ...still got the error case. – aneena Apr 21 '15 at 18:41
  • are you... trying to do a POST to an xml file? http://stackoverflow.com/a/12000090/526704 – DLeh Apr 21 '15 at 18:45
  • yes post to a local xml file ... – aneena Apr 21 '15 at 19:05
  • 1
    that's not going to work. an XML file is not a web server. – DLeh Apr 21 '15 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. – aneena Apr 21 '15 at 19:18

1 Answers1

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

Community
  • 1
  • 1
Smalltree1989
  • 1,108
  • 8
  • 9