SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Get more than one variables through response?

    I'm creating a login script in which I get an response=="success" if everything is OK, but I also want to get the users id... Is this possible?
    Code JavaScript:
    $.ajax({
    			type: "POST",
    			url: action,
    			data: form_data,
    			success: function(response)
    			{
    				if(response == 'success')
    					$("#form1").slideUp('slow', function() {
    						$("#message").html("<p class='success'>You have logged in successfully!</p>");
    					});
    				else
    					$("#message").html("<p class='error'>Invalid username and/or password.</p>");	
    			}
    		});

    THanks in advance :-)

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    A potentially easy way is to return -1 for a failed one, or the userid itself for a successful one.

    That way you cold do something like:

    Code javascript:
    var userId = Number(response);
    if (userId > 0) {
        // success
        ...
    } else {
        // invalid
        ...
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •