[Dojo-interest] XMLHTTPTransport Error: 0, Type: unknown

Thomas Wolf tw at wsf.at
Mon Feb 12 08:35:50 MST 2007


Spiros Papadopoulos wrote:
> On 11/02/07, *Thomas Wolf* <tw at wsf.at <mailto:tw at wsf.at>> wrote:
> 
>     How do you call insert_exists()? I tried to reproduce
>     your situation and got the same error under certain
>     circumstances when coding:
>     <form id="test" onsubmit="insert_exists(this)">
>     while:
>     <form id="test" onsubmit="return(insert_exists(this))">
>     worked reliably.
> 
>     Thomas
> 
> 
> Thanks a lot for your reply. I was away for the weekend, didn't have
> Internet and just checked my e-mail.
> 
> I tried with the return(insert_exists(this)) but didn't work.
> 

Yes, I realized meanwhile that this was only a part of the problem ;(
I thinke there are two problems in your code:
1) the bind() call works asynchronous by default, so your code doesn't
wait for the server's response but immediately submits the form.
2) With your "return true/false" statements, you don't leave
checkInputs() but just the "load: function()" - therefore checkInputs()
always returns 'undefined'.

My suggestion would be to change the bind() call to be sync (setting
sync: "true") and set a return variable during the load: event.

I have set up a very rough test at http://www.wsf.at/test/sp.php
based on your code. A digit in the 'name' field is treated as 'exists',
any letter as 'not exists'.

HTH
Thomas


> This is how i call the function:
> <FORM onSubmit="javascript: checkInputs(this);"
> NAME="addpersonFrm" ID="addPersonFrm" ACTION="<?php echo
> $_SERVER['PHP_SELF']."?addr"; ?>" METHOD="post">
> 
> Since it worked for a while...(!!) i implemented some of the code that i
> want in the load function. 
> I leave this here, even if this is only testing code and i think that has nothing to do with the error since
> I've commented out before. Point is that alert(data); should print
> exists or not exists as appropriate. Anyway..
> 
> The checkInputs() func was inside index.php file. From there i was
> calling insert_exists(), after other
> validation checks. Since it stopped working again and for two days i
> tried many things
> (..even changed the name of the function to make sure the underscore :(
> doesn't affect anything, ...I know...
> it's called desperation) i also added all validation checks into this
> one function and changed the name.
> I omit those checks here. After the changes this is how the function is
> at the moment:
> 
> function checkInputs(tform) {
> 
> /* Several other validation checks here, also return false if sth wrong.
> This works! */
> 
> var urlstr = "http://localhost/folder/folder/scripts/contactexists.php?";
> /* i mainly use: var urlstr = "scripts/contactexists.php?"; */
> 
> var elVal;
> var elName;
> for(var x = 0; x < tform.elements.length; x++) {
>         elVal = tform.elements[x].value;
>         if(elVal != "") {
>                elName = tform.elements [x].name;
>                if(elName != "") {
>                        if(elName != 'addrType' && elName != 'country')
>                                urlstr += elName+"="+elVal+"&";
>                }
>        }
> }
> urlstr = urlstr.substring(0, urlstr.length -1);
> 
> if(urlstr.length > 0) {
>         dojo.require("dojo.io.*");
>         dojo.require("dojo.dom");
> 
>         alert(urlstr);   //this prints:
> scripts/contactexists.php?fname=Spiros&email=spap13 at googlemail.com
> <mailto:spap13 at googlemail.com>
>                            //or
> http://localhost/folder/folder/scripts/contactexists.php?fname=Spiros&email=spap13@googlemail.com
> <http://localhost/folder/folder/scripts/contactexists.php?fname=Spiros&email=spap13@googlemail.com>
>         dojo.io.bind ( {
>                  url: urlstr,
>                  mimetype: "text/plain",
>                  method: "GET",
>                  transport: "XMLHTTPTransport",
>                  error: function(type, error, httpObj) {
>                            dojo.debug("Error: "+error.message+" and
> Type: "+error.type);
>                   },
>                  load: function(type, data, httpObj) {
>                            var message = data;
>                            if(message == "not exists")
>                                     return true;
>                            
>                            var row = document.createElement('tr');
>                            var cell = document.createElement('td');
> 
>                             cell.innerHTML = message;
>                            cell.setAttribute("id", "existsCell");
>                            cell.setAttribute("class", "cell");
>                             row.appendChild(cell);
>                            dojo.dom.insertBefore(row,
> document.getElementById("secRow"));
>                            return false;
>                   }
>          } );
>     }
> }
> 
> The contactexists.php, which if i call from the browser works:
> 
> /* to start, only checking if name is given */
> if(isset($_GET['fname'])) {
> 
>       /* several if() to construct query depending on the given
> data...omitted */
> 
>       $result = mysql_query($query) or die(mysql_error());
>       if(mysql_fetch_array($result)) {
>               print "person exists";
>       }else{
>               print "not exists";
>     }
> }/* I even put a print here to make sure it is not the above code */
> else {
>      print "i print this";
> }
> 
> I don't believe this is it, but just in case, can the POST method used
> on the form
> interfere with the GET in the function?
> This must be something stupid...! I cannot understand how 2 other functions
> which, OK, do different things, BUT in the same exactly way.. work
> perfectly.
> 
> Thank you
> Spiros
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Dojo FAQ: http://dojo.jot.com/FAQ
> Dojo Book: http://manual.dojotoolkit.org/DojoDotBook
> Dojo-interest at dojotoolkit.org
> http://dojotoolkit.org/mailman/listinfo/dojo-interest



More information about the Dojo-interest mailing list