When it comes to my AJAX development, I rely on prototype and utilize the following code:
somefunction: function(){
var result = "";
myAjax = new Ajax.Request(postUrl, {
method: 'post',
postBody: postData,
contentType: 'application/x-www-form-urlencoded',
onComplete: function(transport){
if (200 == transport.status) {
result = transport.responseText;
}
}
});
return result;
}
However, I noticed that "result" ends up being an empty string. In an attempt to resolve this issue, I adjusted the code as follows:
somefunction: function(){
var result = "";
myAjax = new Ajax.Request(postUrl, {
method: 'post',
postBody: postData,
contentType: 'application/x-www-form-urlencoded',
onComplete: function(transport){
if (200 == transport.status) {
result = transport.responseText;
return result;
}
}
});
}
Despite making these changes, I still encountered the same problem. How can I access the responseText for use in other methods?