View Full Version : jQuery: XML data, post(), and each()

06-28-2009, 04:00 AM
this is the xml data being processed from 'comment_add_xml.php',

<result>Please leave an email.</result>
<result>Please leave a content.</result>

this is the jquery code supposed to post data from a html form below, it post the data from the form to 'comment_add_xml.php', then grab the xml data from it, and then display the data on the form again,

this.commentAdd = function(){
$("#result_comment").html('<div class="ajaxloader"><p><img src="img_iconies/loader_0.gif"/> loading...</p></div>');
return false;

function addMessages(xml) {
$("error",xml).each(function(i) {
temp = $("error",xml).text();

addMessages(xml) is not finished yet bcos above it should 'break' each error and result into individual elements, but instead, it joins them up together like this,

error=> comment_emailcomment_content

result=> Please leave an email.Please leave a content.

Am I using the correct jquery function to process the xml data above - each()?? how can I break them into individual elements??

this is html form,

<form action="#" onsubmit="commentAdd(); return false;" method="post" enctype="multipart/form-data" id="form_comment">

<div class="form_item">
<label class="title" id="comment_email_label">
<input id="cmt_email"/>&laquo; Email
</label><img src="img_iconies/attention.png" style="visibility:hidden;" id="comment_email_img"/>

<div class="form_item">
<label class="title" id="comment_content_label">
<textarea id="cmt_content"></textarea>
</label><span style="visibility:hidden;" id="comment_content_img"> </span>

<div class="form_item">

<div class="form_left">
<input type="submit" name="update" value="Submit" class="button button_submit "/>
<input id="pg_id" name="pg_id" type="hidden" value="<?php echo $_REQUEST['pg_id'];?>" />

<div id="result_comment" class="form_right"></div>

please let me know if u have any ideas.

many thanks,