SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Jquery json form processing

    Howdy

    If this is obvious - please excuse me...

    This the the JS

    The form is processed - backside php works
    but this but does not do what I want...what am I missing?


    $(document).ready(function() {
    $("#loginForm").validate({
    errorLabelContainer: "#errorMessage",
    wrapper: "li",
    rules: {
    username: "required",
    password: "required"
    },
    messages: {
    username: "Please enter your username.",
    password: "Please enter your password."
    },
    submitHandler: function(form) {
    $.ajax ({
    type: 'post',
    url: 'auth_user.php',
    dataType: 'json',
    success: function(json) {
    if(json.error === true) {
    $("#errorMessage").text = json.msg;
    } else {
    $(location).attr('href',json.url);
    }

    },
    });
    }
    });
    false;
    });

  2. #2
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You can use the code tags to wrap your code to be viewed better like so:
    Code:
    $(document).ready(function() {
    	$("#loginForm").validate({
    		errorLabelContainer: "#errorMessage",
    		wrapper: "li",
    		rules: {
    			username: "required",
    			password: "required"
    		},
    		messages: {
    			username: "Please enter your username.",
    			password: "Please enter your password."
    		},
    		submitHandler: function(form) {
    			$.ajax ({
    				type: 'post',
    				url: 'auth_user.php',
    				dataType: 'json',
    				success: function(json) {
    					if(json.error === true) {
    						$("#errorMessage").text = json.msg;
    					} else {
    						$(location).attr('href',json.url);
    					}
    				},
    			});
    		}
    	});
    	false;
    });
    Now, onto your question. (Answers are off the top of my head....)

    1. $("#errorMessage").text = json.msg;
    jQuery does this - $("#errorMessage").text(json.msg);

    2. You have a false just sitting there, why?

    3. $(location).attr('href',json.url); I believe should be:

    window.location = json.url;


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
  •