Before I buy the license, the DHTMLAjax does not work with text responses, and the documentation is horribly vague on it. I attempted to get support in the forum and all I got was a pointer to a sample that was for XML with a caveat that I needed to use responseXML with no explanation as to what else you have to change. So this is meaning so far you can’t capture the response into a variable. It is quite obvious that the developer preferred XML. I don’t. That’s just another set of programming I would have to learn. What I would like to see is ajax debugged to work with string or json encoded arrays for the POST method. Then I would love to see EXAMPLES of all the available return formats posted.
I also recommend the canned responses go away in the forum. The admin keeps referring people to samples that are horribly vague and so often do not present the right solution.
Correction to above: responseText NOT responseXML
so far you can’t capture the response into a variable
Actually you can
docs.dhtmlx.com/doku.php?id=dhtm … dhtmlxajax
//async
dhtmlxAjax.get("some.php", function(loader){
var text = loader.xmlDoc.responseText; //response as text
})
//sync
var text = dhtmlxAjax.getSync(url).xmlDoc.responseText;
Now I tried that and didn’t get a response when I tried to echo the response in a javascript error message.
To test this in the php it is simple either die(‘OK’); or echo ‘OK’; but neither of them are picked up. I need to be able to grab the responses into a variable on the sending end. So I guess what the question should be now, is exactly what has to be in the process file for it to be picked up. Can you provide a simple text file that echos the response.
Also, I use the post method which is my preference because I can provide complex responses sometimes. An example:
echo json_encode(array(‘result’ => ‘Private Message Sent’));
Because the result is not ‘OK’ what I am trying to do is get it to generate the standard error message.
my assumption in the javascript is this should be picked up in the form file as html.response
In standard ajax I do another parameter:
//define data type
dataType: ‘json’,
Does this need to be set too?
Here is what I got so far and it is NOT working:
<script src="../script/dhtmlxcommon.js"></script>
<script>
function outputResponse(loader){
if(loader.xmlDoc.responseText!=null)
alert("We Got Response\n\n"+loader.doSerialization())
else
alert("Response contains no XML")
}
function sendRequestPost(sync){
if(sync==true){
dhtmlxAjax.post("process/process.user-message.php",encodeURI(getFormValues()),outputResponse);
alert("Request Sent");
}else{
var loader = dhtmlxAjax.postSync("process/process.user-message.php",encodeURI(getFormValues()));
alert("Request Sent");
outputResponse(loader)
}
}
function getFormValues(){
var strparams;
//var email = $("input#email").val();
var strsendtype = document.getElementById("sendtype").value;
var strsubject = escape(document.getElementById("subject").value);
var strsubject = escape(document.getElementById("message").value);
strparams = 'sendtype='+strsendtype+'&subject='+strsubject+'&message='+strsubject+'&uid='+<?=$user_id;?>;
return strparams;
}
function strtrim(str) {
return str.replace(/^\s+|\s+$/g,"");
}
function sendRequest(){
sendRequestPost(true);
}
</script>
The outputResponse function fails to execute. All I get is that the “Request sent”
Right now I set “process/process.user-message.php” to simply echo “OK”.
Here is what I did and using the GET method, it finally does work and I can capture the response from the server process file if needed:
function sendRequest(){
var url = "process/process.user-message.php?"+encodeURI(getFormValues());
var loader = dhtmlxAjax.getSync(url);
var response = loader.xmlDoc.responseText;
alert(response);
}
function getFormValues(){
var strparams;
//var email = $("input#email").val();
var strsendtype = document.getElementById("sendtype").value;
var strsubject = escape(document.getElementById("subject").value);
var strsubject = escape(document.getElementById("message").value);
strparams = 'sendtype='+strsendtype+'&subject='+strsubject+'&message='+strsubject+'&uid='+<?=$user_id;?>;
return strparams;
}
function strtrim(str) {
return str.replace(/^\s+|\s+$/g,"");
}