SitePoint Sponsor |
|
User Tag List
Results 1 to 16 of 16
Thread: Can someone explaint hthem???
-
Mar 20, 2007, 06:56 #1
- Join Date
- Aug 2006
- Location
- India
- Posts
- 488
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Can someone explaint hthem???
Hello everyone,
I am trying to submit my form with AJAX POST request and stuck with two errors which i am seeing in firefox
Error: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://h/php/validate.js :: handleHttpResponse :: line 85" data: no]
Source File: h/php/validate.js
Line: 85
line 85: if(http.status == 200)
Error: uncaught exception: [Exception... "Component returned failure code: 0x804b000f [nsIXMLHttpRequest.setRequestHeader]" nsresult: "0x804b000f (<unknown>)" location: "JS frame :: http://h/php/validate.js :: validateMe :: line 64" data: no]
line 64: http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
i think in ajax this is a correct syntax but still it throws these error !!
Can i make ajax request like below
for (var iCounter=0; iCounter<form.length; iCounter++)
{
if(document.form1.elements[iCounter].type=='text')
{
alert("calling validateme for "+document.form1.elements[iCounter]);
validateMe(document.form1.elements[iCounter]);
}
}
if that alert i will hide it will submit the form even if it is not validated and if i kept this alert it will show the proper message and prompt user to input the correct fields.
Anybody any idea???????
Thanks & Regards,
Priti
-
Mar 20, 2007, 07:07 #2
never used post always used get method for ajax.
-
Mar 20, 2007, 09:02 #3
- Join Date
- Mar 2001
- Posts
- 3,537
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
never used post always used get method for ajax.
priti,
I suggest you write a simple js script that makes an xhr using post that sends two name=value pairs to the server. Have your server side script send those values back as the response, and then have your js script alert() the values.
You need to be able to get something simple like that to work before proceeding.
-
Mar 20, 2007, 11:09 #4
- Join Date
- Apr 2001
- Location
- Devon, UK
- Posts
- 333
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Incidentally, AJAX POST is fine and should be used if you are sending a lot of data. GET is more typically used though.
-
Mar 20, 2007, 11:54 #5
- Join Date
- Nov 2004
- Location
- Nelson BC
- Posts
- 2,310
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
For the first error, that might be caused if you are checking the .status property BEFORE the .readyState == 4.
The second error can happen in FireFox if you execute another AJAX request before a previous one completes. I'd try adding http.abort() before you .setRequestHeader or .open
Are you validating each form field by ajax individually? That sounds like it might be a bad idea. Why not send the entire form for validation at once?
-
Mar 20, 2007, 12:56 #6
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
You should use GET if you are retrieving information and POST if you are updating anything on the server.
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
-
Mar 20, 2007, 22:51 #7
- Join Date
- Aug 2006
- Location
- India
- Posts
- 488
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hello everyone,
First of all i would like to thanks everyone who has put their interest in this...
But i was trying to submit my form with AJAX POST request because i have to use it in my next project and two fields are giving me tuff time to deal with ajax post request.
GET is working fine but i have a long form to submit hence i have to use POST....i knew when to post and get but i want to use POST thats why i am trying a example first to make me understand how to do it but finding a gr8 diffcult time to do this.
:-(
anyone can please share their knowledge about this error and how to fix it if u want me i can post the whole code also.Let me know !!
Regards,
-
Mar 20, 2007, 23:02 #8
Visit this and look at the codes and try them at your side.
http://www.xul.fr/en-xml-ajax.html
Hope this will help yoiu....Best Joomla Web Design and Development Agency :--:
PSD to Joomla :--: Award Winning Web Design Company
-
Mar 20, 2007, 23:34 #9
- Join Date
- Aug 2006
- Location
- India
- Posts
- 488
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
No the status property is after readystate.well adding it doesn't worked out for me :-(
I think adding alert give sufficient time for response to arrive and hence it works fine when i keep this alert message with http.abort it simply abort the request rather then that i would like that it should wait for some time till response is arrived do u know anything in ajax method or property which help us in this???i tested with firebug and found it happends to be it make request and then two errors uncaught exception and then the response from the server in inner HTML ..Ahh
Somethings silly i am missing i suppose huh....??
this is getting interested now does anyone faced this problem before i don't think i am the first one but i would like to know how it has to be solved.I think sitepoint has number of gud people on ajax because i learn a lot of articles from this and i wish someone can better guide me here.
Regards,
-
Mar 21, 2007, 06:42 #10
- Join Date
- Feb 2007
- Location
- Brooklyn, NY
- Posts
- 22
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I have received that error a number of times and the problem was usually in my server side code. There was always some problem with the query and the server side code receiving it. Or just an error in the server code itself.
It can be a bear to debug when using post.
-
Mar 21, 2007, 10:49 #11
- Join Date
- Nov 2004
- Location
- Nelson BC
- Posts
- 2,310
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Does it work in IE?
-
Mar 22, 2007, 02:34 #12
- Join Date
- Aug 2006
- Location
- India
- Posts
- 488
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
AJAX probs continuessssssssssssss
With that alert statment it works fine.
PHP file to handle resquest
PHP Code:<?php
/*This is a dummy code to handle the request*/
$method=$_POST["req"];
if($method=='POST')
{
$required = $_POST["sRequired"];
$typecheck = $_POST["sTypeCheck"];
$val = $_POST["val"];
}else
{
$required = $_GET["sRequired"];
$typecheck = $_GET["sTypeCheck"];
$val = $_GET["val"];
}
$res='';
if($typecheck=='email' && !empty($val))
{
$resq=validateEmail($val);
}
if(empty($val) && $required=='required')
{
$res='Required Fields';
}
else
{
if(empty($res))
$res=$resq;
else
$res='OK';
}
echo trim($res);
function validateEmail($val)
{
if (ereg ("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", $val))
{
$em='OK';
}
else
{
$em="Invalid Email Address";
}
return $em;
}
?>
HTML Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Ajax Form</title> <script type="text/javascript" src="validate.js"></script> </head> <body> <fieldset> <legend>Ajax Form</legend> <form name="form1" id="form1" method="post" action="formvalidation.php" onSubmit="javascript: return attachFormHandlers();"> <table width="500"> <tr><td><div id="gShow"></div></td></tr> <tr> <td width="130">Username </td> <td width="170"><input type="text" name="user" tabindex="1" id="user" class="validate required none usermsg"/></td> <td id ="usermsg" class="rules"></td> </tr> <tr> <td>Email </td> <td><input type="text" name="email" tabindex="2" id="email" class="validate required email emailmsg" /></td> <td id="emailmsg" class="rules"></td> </tr> <tr> <td><input type="submit" name="Submit" value="Submit" tabindex="5" /></td> </tr> </table> </form> </fieldset> </body> </html>
Code://window.onload = attachFormHandlers; var gShow; //error handling var sUrl = "formvalidation.php?validationtype=ajax&val="; var gErrors = 0; var http http = getHTTPObject(); function attachFormHandlers() { //alert("in attach"); var form = document.getElementById('form1'); if (document.getElementsByTagName) { var objInput = document.getElementsByTagName('input'); for (var iCounter=0; iCounter<form.length; iCounter++) { if(document.form1.elements[iCounter].type=='text') { alert("calling validateme for "+document.form1.elements[iCounter]); validateMe(document.form1.elements[iCounter]); } } } if(gErrors<=0) { document.form1.submit(); return false; } else { alert("Fill all Required fields"); return false; } } /*validateMe is the function called with onblur each time the user leaves the input box passed into it is the value entered, the rules (which you could create your own), and the id of the area the results will show in*/ function validateMe(objInput) { var str; sVal = objInput.value; //alert(sVal); sRules = objInput.className.split(' '); sRequired = encodeURI(sRules[1]); sTypeCheck = encodeURI(sRules[2]); //typecheck are additional validation rules (ie. email, phone, date) gShow = sRules[3]; /*Post*/ str=sUrl + sVal + "&sRequired=" + (sRequired) + "&sTypeCheck=" + sTypeCheck + "&req=POST"; http.open("POST","formvalidation.php",true); http.setRequestHeader("Content-type","application/x-www-form-urlencoded"); http.setRequestHeader("Content-length",str.length); http.setRequestHeader("Connection", "close"); http.onreadystatechange=handleHttpResponse; http.send(str); /*GET http.open("GET", sUrl + (sVal) + "&sRequired=" + (sRequired) + "&sTypeCheck=" + sTypeCheck, true); http.onreadystatechange = handleHttpResponse; // handle what to do with the feedback http.send(null); */ } function handleHttpResponse() { if (http.readyState == 4) { if(http.status == 200) { sResults = http.responseText.split(","); //results is now whatever the feedback from if(sResults[0] != 'OK') { gErrors = gErrors + 1; document.getElementById(gShow).innerHTML=http.responseText; return false; } } else if (http.status == 404) { alert ("Requested URL is not found."); return false; } else if (http.status == 403) { alert("Access denied."); return false; } else { document.getElementById(gShow).innerHTML="status is : "+http.status; return false; } } return false; } function getHTTPObject() { var xmlhttp=null; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } return xmlhttp; }
Would be a great help
Regards,Last edited by Jelena; Mar 22, 2007 at 03:21.
-
Mar 22, 2007, 02:52 #13
Hello priti,
I have just tried your code and working fine at my side.Best Joomla Web Design and Development Agency :--:
PSD to Joomla :--: Award Winning Web Design Company
-
Mar 22, 2007, 03:20 #14
Sorry it was my mistake.
When I remove alert it is really not working...Best Joomla Web Design and Development Agency :--:
PSD to Joomla :--: Award Winning Web Design Company
-
Mar 22, 2007, 03:35 #15
It is not working while we remove alert so it is telling us that ajax response take some time to come.
So your following code is executed before response comes from ajax function:
Code:if(gErrors<=0) { document.form1.submit(); return false; } else { alert("Fill all Required fields"); return false; }
If you comment the following statement in this code then you will be able to see the actual thing that what is happening:
document.form1.submit();
Between,
I have found a good ajax form validation example where all the process has been nicely explained.
http://cristian.nexcess.net/ajax/validate/index.php
Hope this helps...Best Joomla Web Design and Development Agency :--:
PSD to Joomla :--: Award Winning Web Design Company
-
Mar 25, 2007, 23:47 #16
- Join Date
- Aug 2006
- Location
- India
- Posts
- 488
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hmmm well thanks a lot for the links it was quite informative and i just made change in myjs and php and now its rocking :-)
I must thanks all of the people who cared to help me and specially SSJ who tried to run the code and spend time to find the erroneous line.Now no uncaught exception and nothing just smooth ride:-)
Again expressing my thanks to all sitepoint members
Best regards,
Bookmarks