Results 1 to 4 of 4

Thread: jQuery ajax help

  1. #1
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default jQuery ajax help

    I really struggle with jQuery so just stick with me.

    Code:
    <script type="text/javascript">
    jQuery(function($){
    	var field1 = $('#loginUser');
    	var field2 = $('#loginPass');
    	$('#loginSubmit').click(function(){
    		jQuery.ajax({
    			url: '<?php echo $host; ?>login.php',
    			type: 'post',
    			data: 'field1value=' + field1.value() + '&field2value=' + field2.value,
    			success: function(results){
    				alert(results);
    				alert("hi");
    			}
    		});
    	});
    });
    </script>
     <form>
     <input type="text" name="username" id="loginUser" value="Username" onclick="clear1(this)" onblur="fill1(this)"> 
     <input type="text" name="password" id="loginPass" value="Password" onclick="clear2(this)" onblur="fill2(this)">
     <input type="button" name="loginSubmit" id="loginSubmit" value="Log In" Style="background-color:brown;border:none;">
     </form>
    It doesn't work. When I click the button nothing happens.
    Any help?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    There could also be other problems but the value of a jQuery form element object is .val() not .value() or .value:

    Code:
    data: 'field1value=' + field1.val() + '&field2value=' + field2.val(),
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Code:
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
    <script type="text/javascript">
    jQuery(function($){
    	var field1 = $('#loginUser');
    	var field2 = $('#loginPass');
    	$('#loginSubmit').click(function(){
    		jQuery.ajax({
    			url: '<?php echo $host; ?>login.php',
    			type: 'post',
    			data: 'field1value=' + field1.val() + '&field2value=' + field2.val(),
    			success: function(results){
    				alert(results);
    				alert("hi");
    			}
    		});
    	});
    });
    </script>
    Any html after that just doesn't show up on the page. IE9.
    Any help?

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That is not happening here:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
    <script type="text/javascript">
    jQuery(function($){
    	var field1 = $('#loginUser');
    	var field2 = $('#loginPass');
    	$('#loginSubmit').click(function(){
    		jQuery.ajax({
    			url: '<?php echo $host; ?>login.php',
    			type: 'post',
    			data: 'field1value=' + field1.val() + '&field2value=' + field2.val(),
    			success: function(results){
    				alert(results);
    				alert("hi");
    			}
    		});
    	});
    });
    </script>
    </head>
    <body>
    hello
    </body>
    </html>
    It could be that you have an unclosed html comment token:

    Code:
    <!--
    somewhere in the source code of your page. Some browsers will error correct for that depending upon the circumstances.

    If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •