Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 812023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:08:17+00:00 2026-05-15T01:08:17+00:00

I am learning how to use JQuery to help check data availability. To start

  • 0

I am learning how to use JQuery to help check data availability.
To start with it, I wrote a few lines of codes using cakePHP.

I have written a function in a Controller for checking data input,
and the URL is like this:
http://www.mywebsite.com/controllers/action/avariable

I was trying to pass the value in a Input TextBox field using the JQuery Ajax to the URL above,
but I don’t know why it is not working in passing a variable to the Controller’s action.
Could you help me out please?

<Script language="javascript">
//<!--
$(document).ready(function(){  
$(document).change(function() { 
var usr = $("#data\\[User\\]\\[name\\]").val();
if(usr.length >= 3){ 
$("#username").append('<span><img align="absmiddle" src="loader.gif" />Checking</span>');

$.ajax({ 
type: "POST",
url: "http://www.mywebsite.com/controllers/action/",
data: usr,
success: function(msg){

     if(msg == 'OK')
     {
     $("#username").append('<span><img align="absmiddle" src="accepted.png"/></span>');
      }
     else
     {
     $("#username").append('<span>'+msg+'</span>');
     }
      } 
     });
      }
else
{
$("#username").append('<span>The username should have at least 3 characters.</span>');
}

});
}); 
//-->
</Script>

<form name="adduser" id="adduser" method="post" action="/controllers/action2">
<table border=0 width="100%">
<tr>
 <td>Username</td>
 <td>       
        <div id="username">
 <input type=text name="data[User][name]" id="data[User][name]">
 </div>       
        </td>
</tr>
<tr>
 <td>
 <input type="submit" value="Send">
 </td>
</tr>
</table>
</form>

Here is the code of the Action:

 function action($uname=null){
                 $result2=$this->__avail($uname);           
                  if($result2==1)
                   {return "OK";}
                   else
                   {return "NOT";}           
            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:08:18+00:00Added an answer on May 15, 2026 at 1:08 am

    Well for one you’re assigning a change event to the document object which isn’t going to do anything. What you probably want is:

    (function($) {
        var timeout;
        var $user = $("#data\\[User\\]\\[name\\]").bind("keyup keydown keypress", function() {
            window.clearTimeout(timeout);
            // Give it a delay since the end user is probably still typing
            timeout = setTimeout(function() {
                ... your ajax logic and length check ...
                ... can use $user here to access the textfield ...
            }, 500);
        });
    )(jQuery);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 424k
  • Answers 424k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There is DFS from Microsoft itself, it's in Windows Server… May 15, 2026 at 11:56 am
  • Editorial Team
    Editorial Team added an answer if ($("#yourCheckboxID").is(":checked")) { // checkbox is checked } else {… May 15, 2026 at 11:56 am
  • Editorial Team
    Editorial Team added an answer Ask for: HTML Files CSS Files tableless design - it… May 15, 2026 at 11:56 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.