-
using response xml tags to validate form
Hello, I'm having this huge problem trying to validate a login form using ajax.
Everything works fine, but I cant use the xml "result" tag data to validate the form. I use an "onsubmit" function to call an ajax "load" funtion that brings me the data I need, that works ok. What I cant do is to have the ajax load fuction return true or false depending on this xml result var. This is my code:
the html:
<script type="text/javascript">
function validate(){
if (!load('login.php','var=x')==0){
return false;
}
return true;
}
</script>
<form id="formLogin" name="formLogin" method="post" onsubmit="return validate();" action="home.html">
//form code
</form>
the js:
function newAjax() {
var xmlhttp=false;
try {
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp=false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp=new XMLHttpRequest();
}
return xmlhttp;
}
function load(target,var) {
var layer=document.getElementById('msg');
var ajax=newAjax();
ajax.open("POST",target, true);
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajax.send(var);
function result(){
if (ajax.readyState==4){
if (ajax.responseXML.getElementsByTagName('result')[0].firstChild.data==1){
layer.innerHTML = "bad";return false;
}else{
layer.innerHTML = "good";
return true;
}
}
}
ajax.onreadystatechange = result;
}
the .php
<?php
header('Content-type: text/xml');
$err = '';
$err .= $HTTP_POST_VARS["var"]."<br>";
$result = 1;
?>
<xmlresponse>
<result><? echo $result; ?></result>
<msg><?
echo '<![CDATA[';
echo $err;
echo ']]>';
?></mensaje>
</xmlresponse>
this programs returns "bad" or "good" depending on $result, but I cant use that to return true or false on the "load" function to validate the form. The onreadystatechange event makes the thing dificult to solve.
Any ideas...?
Please Help.
Similar Threads
-
By ahmed in forum ASP.NET
Replies: 7
Last Post: 09-24-2002, 03:24 AM
-
By Tim in forum xml.announcements
Replies: 0
Last Post: 10-11-2001, 04:00 PM
-
Replies: 1
Last Post: 07-20-2001, 03:21 AM
-
By Jeff Condon in forum XML
Replies: 0
Last Post: 05-29-2001, 02:25 PM
-
By Extensibility in forum web.announcements
Replies: 0
Last Post: 07-20-2000, 06:20 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|