2017-01-23 5 views
0

Ich habe eine XHR-Anfrage. Ich versuche Code auf meinem lokalen Server zu testen.Testen von XMLHttpRequest auf dem lokalen Server

GetMetaData: function() { 
     var xhr = new XMLHttpRequest(); 
     xhr.open("POST", "../?/?.asmx/GetData", true); 
     xhr.setRequestHeader('Content-Type', 'application/json;charset=utf-8;'); 
     xhr.send(JSON.stringify({ 
      "args": JSON.stringify({ 
       method: "?", 
       factors: "?", 
       lcid: app.ResponseParamsValues.lcid, 
      }) 
     })); 

     xhr.onreadystatechange = function() { 
      if (this.readyState == 4) { 
       var response = (JSON.parse(this.responseText).d); 
       app.variables.metaValues = response.Result; 
      } 
      if (this.status != 200) { 
       console.log('error: ' + (this.status ? this.statusText : '?')); 
      } 
     }; 
    } 

Ich versuche, Antwort auf meine .json-Datei auf dem lokalen Server zu ändern. Aber es funktioniert nicht

GetMetaData: function() { 
     return "../../data/data.json"; 
} 
+0

Großen. Aber das ist keine Frage. – Xufox

Antwort

0

Ich benutze es für den Test auf meinem lokalen Server

var xhr = new XMLHttpRequest(); 
xhr.open("GET", "example.json", true); 
xhr.setRequestHeader('Content-Type', 'application/json;charset=utf-8;'); 
xhr.send(); 

xhr.onreadystatechange = function() { 

    if (this.readyState == 4) { 
      var response = JSON.parse(this.responseText); 

      //some actions with the response 
    } 

    if (this.status != 200) { 
      console.log('error: ' + (this.status ? this.statusText : 'request failed')); 
    } 
}; 
Verwandte Themen