Note that there are some explanatory texts on larger screens.

plurals
  1. POjs class - first ajax object, can't get the result
    primarykey
    data
    text
    <p>this is my first class in js and I need help for get the rigth result</p> <pre><code>function ajaxObject (url, data, type) { this.url = url; this.data = 'data='+JSON.stringify(data) || null; this.type = type ? type : 'json'; this.result = null; var self = this; this.create = function () { //se il browser ? firefox if (window.XMLHttpRequest) { //istanzio un nuovo oggetto XMLHttpRequest this.oHttp = new XMLHttpRequest(); if (this.oHttp.overrideMimeType) { this.oHttp.overrideMimeType('text/xml'); } //se il browser ? IE } else if (window.ActiveXObject) { try { this.oHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { this.oHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { } } } }; this.process = function () { if (this.oHttp) { this.oHttp.open("POST", this.url, true); this.oHttp.onreadystatechange = this.manage; if (this.oHttp.overrideMimeType) { this.oHttp.overrideMimeType("application/json"); } this.oHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); this.oHttp.setRequestHeader("Content-length", this.data.length); this.oHttp.send(this.data); } }; this.manage = function () { // alert(self.oHttp.readyState + ' - ' + self.oHttp.responseText); if (this.readyState === 4 &amp;&amp; this.status === 200) { // here this.responseText is correctly populated self.result = this.responseText; } else { self.requestFailed('message', this); return; } }; this.getResult = function () { switch (this.type) { case 'text': return this.result; break; case 'json': return $.parseJSON(this.result); break; } }; this.requestFailed = function (id, request) { if (document.getElementById) { sys.clearContent(id); document.getElementById(id).innerHTML = 'The XMLHttpRequest failed, STATUS: ' + request.status; } }; </code></pre> <p>}</p> <p>I try getting the result in this way:</p> <pre><code>var ao = new ajaxObject('output.php', {mutator: "orders", get: "orders"}); ao.create(); ao.process(); var r = ao.getResult(); alert(r); </code></pre> <p>but I can't get the result I expected.. all the server side works perfectly but my result variable is always "null".. I think there's something I miss, if somebody can help me please :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload