aneena
aneena

Reputation: 197

Writing jquery object to XML

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.

Upvotes: 0

Views: 51

Answers (1)

Smalltree1989
Smalltree1989

Reputation: 1148

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

Upvotes: 1

Related Questions