Enjoy an ad free experience by logging in. Not a member yet?
Register .
01-30-2012, 02:15 PM
PM User |
#16
Senior Coder
Join Date: Dec 2010
Posts: 2,261
Thanks: 10
Thanked 533 Times in 527 Posts
Quote:
Originally Posted by
jackvan
It's exactly like this:
url: "/cgi-bin/isaccount.cgi?username=jack",
Sorry, but you don't get me
Code:
It's not exactly like this
url: "/cgi-bin/isaccount.cgi?username=$name::getName()"
which would involve a method execution instead of a simple variable name
01-30-2012, 02:38 PM
PM User |
#17
New Coder
Join Date: Jan 2012
Posts: 24
Thanks: 1
Thanked 1 Time in 1 Post
I've just tested my script with your solutions:
url:"/cgi-bin/isaccount.cgi?username=" + encodeURIComponent(name.val()),
or
url:"/cgi-bin/isaccount.cgi",
data : {username: name.val()},
They don't work:
1) url:"/cgi-bin/isaccount.cgi?username=" + encodeURIComponent(name.val()),
I entered: abcd in the name field of the Form,
My Perl script, isaccount.cgi received two data: name.val() and usernameabcd immediately one after another??
2) url:"/cgi-bin/isaccount.cgi",
data : {username: name.val()},
It did not send any data to isaccount.cgi and it also seems like it did not get into the success:function(data){ loop, i.e. it is not success.
Any idea to fix it?
01-30-2012, 02:52 PM
PM User |
#18
Senior Coder
Join Date: Dec 2010
Posts: 2,261
Thanks: 10
Thanked 533 Times in 527 Posts
Please show the full code of the ajax call and the corresponding form HTML
I don't know about .cgi scripts, but in PHP the data would be available as $_GET["username"] or $_POST["username"] respectively depending on the type of request. Did you provide a type?
Code:
$.ajax({url: "...",
type: "GET",
data: {username: ...},
...
});
01-30-2012, 02:55 PM
PM User |
#19
New Coder
Join Date: Jan 2012
Posts: 24
Thanks: 1
Thanked 1 Time in 1 Post
Correction:
The first method works with some a minor problem:
url:"/cgi-bin/isaccount.cgi?username=" + encodeURIComponent(name.val()),
When I entered: reggy
I got: usernamereggy without an equal "=" between, i.e. I should be getting: username=reggy
Any idea to fix it?
01-30-2012, 03:08 PM
PM User |
#20
Senior Coder
Join Date: Dec 2010
Posts: 2,261
Thanks: 10
Thanked 533 Times in 527 Posts
Obviously your .cgi is reading the values differently than usual. Try this
Code:
url:"/cgi-bin/isaccount.cgi?" + encodeURIComponent(name.val()),
01-30-2012, 03:09 PM
PM User |
#21
New Coder
Join Date: Jan 2012
Posts: 24
Thanks: 1
Thanked 1 Time in 1 Post
No, I did not use type in the Ajax loop. That was the problem.
After I insert: type: "GET", I'm getting proper data:
username=john
username=jack
username=peggy
etc
Sorry for the confusion.
01-30-2012, 03:26 PM
PM User |
#22
New Coder
Join Date: Jan 2012
Posts: 24
Thanks: 1
Thanked 1 Time in 1 Post
I've one other problem. Here's the code:
PHP Code:
//On blur
name . blur ( validateName );
email . blur ( validateEmail );
pass1 . blur ( validatePass1 );
pass2 . blur ( validatePass2 );
//On key press
name . keyup ( validateName );
name . keyup ( validateName );
pass1 . keyup ( validatePass1 );
pass2 . keyup ( validatePass2 );
message . keyup ( validateMessage );
function validateName (){
//if it's NOT valid
if( name . val (). length < 4 ){
name . addClass ( "error" );
nameInfo . text ( "We want names with more than 3 letters!" );
nameInfo . addClass ( "error" );
return false ;
}
//if it's valid
else{
$. ajax ({
url : "/cgi-bin/isaccount3.cgi?username=" + encodeURIComponent ( name . val ()),
type : "GET" ,
async : false ,
success :function( data ){
name . removeClass ( "error" );
nameInfo . removeClass ( "error" );
if( data == "yes" ){
nameInfo . text ( "name ok" );
nameInfo . removeClass ( "error" );
}
if( data == "no" ) {
nameInfo . text ( "Name In Use" );
}
return true ;
}
});
return true ;
}
}
The user is required to enter a username with a minimum 4 characters, if it is valid than it will check the availability of the username.
Here's the problem. When I enter username longer than 4 characters, e.g. "peggy", I may get 2 data: "username=pegg" and "username=peggy".
Any idea to fix it?
Users who have thanked jackvan for this post:
01-30-2012, 05:51 PM
PM User |
#23
New Coder
Join Date: Jan 2012
Posts: 24
Thanks: 1
Thanked 1 Time in 1 Post
I've fixed the problem by changing keyup() to focus():
PHP Code:
//On focus
name . focus ( validateName );
name . focus ( validateName );
pass1 . focus ( validatePass1 );
pass2 . focus ( validatePass2 );
message . focus ( validateMessage );
I've learned a lot from you. My Form Validation is working wonderfully. Thanks again for your time.
Last edited by jackvan; 01-30-2012 at 05:53 PM ..
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 07:36 AM .
Advertisement
Log in to turn off these ads.