Hello all, I'm still relatively new to the world of developing websites (about 9 months now) and I've just discovered jQuery. Looks fantastic and an easy way to save me writing a lot of Javascript.
I wrote a demo login system, just for me to learn and as some example code I could show to prospective employers, with my own Ajax code in it. It worked great. All it does is send 2 variables to another page, ajax.php, which in turn echo's out the new information to be placed in the specified div. Now I'm trying to take out my code and use jQuery's Ajax, however I cannot get it to work and from the examples in the documentation I believe it should.
Can someone please take a look at this code and tell me why it isn't working?
- function funcValUser(user) {
- $(document).ready(function(){
- if(user.length < 5 || user.length > 24) {
- alert("Usernames must be between 5 and 24 characters. \nPlease enter a valid username.");
- }
- var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?~_";
- for(var i = 0; i < user.length; i++) {
- if(iChars.indexOf(user.charAt(i)) != -1) {
- alert ("Usernames must only contain alphanumeric charactes. \nPlease enter a valid username.");
- $.post("includes/ajax.php", { action: 4, info: 1 },
- function(data) {
- $('.ajaxResult1').html(data);
- }
- );
- return false;
- }
- }
- $.ajax({
- url: 'includes/ajax.php',
- data: { action: 1, info: user },
- success: function(data) {
- $('.ajaxResult1').html(data);
- }
- });
- return true;
- });
- }
As you can see I've tried to use 2 different methods for the 2 different Ajax calls, $.post in one and $.ajax in the other but neither seems to work.