Generate XML document in-memory with JavaScript

前端 未结 5 558
谎友^
谎友^ 2020-11-27 13:15

I am working on a Web application that needs to send XML to a server backend. I\'d like to build a XML document in-memory on the client-side, but using XML manipulation rout

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 13:35

    Have you considered JSON? You could save the data using objects. Then you could use JSON.stringify(obj); and send that to the server.

    a simple example

    var obj = new student('Alice',80);
    
    function student(a,b){
      this.name=a;
      this.grade=b;
    }
    
    function sendToServer(){
      var dataString = JSON.stringify(obj);
      //the HTTP request
    }
    

提交回复
热议问题