Bananas Development Blog: share your thoughts

Mootools,Ajax und XML

Bin gerade dabei mit mootools zu experimetieren.
Ajax an sich ist nicht das Problem, nur wie das bei MooTools funktioniert ist mir nicht gleich klar gewesen.

Dann kam noch das Problem wir bekomme ich den Rückgabewert des Requests als XML ?

Hier ist die Lösung (mootools response xml):
<script type="text/javascript">
document.getElementById('commentForm').addEvent('submit', function(e) {
new Event(e).stop();

// this is special. the form needs the request url as action to get this to work
this.send({ onComplete: showResponse });
});

function showResponse (originalRequest,responseXML) {
alert(originalRequest);
alert(responseXML);

}
</script>


Das obige Beispiel ist ein spezial Fall: Ajax.Form.
Dabei muss beachtet werden, dass die form eine Action url besitzt. Und zwar die URL auf die das XMLHttpRequest zugreift !
Darauf muss man erster mal kommen !

Um nun an die Rückgabe des Requests zu kommen muss man die option onComplete benutzen. Denn bei der option update wird einfach der Rückgabewert mit innerHTML in ein Element geschrieben.
Die bei onComplete definierte Funktion braucht nun 2 Parameter. Der erste ist der Rückgabewert als Text und der Zweite als XML.

Banana out
  • No comments

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Trackbacks / Pingbacks

  • No Trackbacks