I'm learning how to do Ajax with Jquery to validate a Form.
First it checks the format of the username to see if it is an valid format, if the format is correct than use Jquery Ajax to check a script to see if the username is available or not.
When the above Script was run, it can get into the success:function(data) loop, but it will not return the data from the
username_check_script_url??
The followings is a test script to illustrate the problem:
PHP Code:
function validateName(){
//if it's NOT valid
if(name.val().length < 4){
alert("We want names with more than 3 letters!");
return false;
}
//if it's valid, check name available or not
else{
The intention of the script is if I enter a name with more than 3 letters, it will fetch "ajax.txt", then return the data in "ajax.txt" which is "OK to use" and shows in the alert message.
But when I enter "abcd" in the Form, I get a pop-up warning message: "data" instead of "OK to use"??
It appears that Ajax communicated with "ajax.txt", but when it gets into the success:function(data){ loop, it is not returning the data from the "ajax.txt"?
Kindly help to explain what I did wrong and how to fix the problem?
I want to send username data entered in the Form to a script which will then check the database for username availability. I've trouble getting it work.
Here's what I did:
PHP Code:
var name = $("#name");
$.ajax({
url:"/cgi-bin/isaccount.cgi?name.val()",
async:false,
success:function(data){
The intention is to send the value of name to the script, isaccount.cgi for it to check username availability. It does not work because the value of name.val() is not passed to the script isaccount.cgi.
I don't think removing the " " in the following line will work:
url:"/cgi-bin/isaccount.cgi?name.val()",
There is no special difference. You can use both (as long as you use them in pairs) for strings. It makes life easier if you want to use quotes inside string literals, as you can just use the other one as the string delimiter
would not just be using the variable "name" but it would also incorporate the execution of the method val() of the variable. Is something like this possible in Perl?
The variable in Javascript is "name" and in Perl it's "$name". I get that. But you thought that also name.val() was possible inside "" quotes which is the result of the execution of a method and not only a variable. Is something like this possible in Perl?