#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    38
    Rep Power
    3

    JQuery, AJAX and JSON simple question


    Hi, I am starting to learn jQuery, AJAX and JSON. I am trying to pass a variable to a PHP script called validate_user.php using the jQuery, AJAX, JSON technique. I keep getting the error SyntaxError: JSON.parse: unexpected character. I have tried a lot of ways to make it work.. and this is the code for the ajaxSubmit.js

    Code:
    $(document).ready(function(){
    $('#loginbutton').click(function() {
    $('#waiting').show(100);
    $('#login-box').hide(0);
    $('#message').hide(0);
    
    $.ajax({
    type: 'POST',
    url: 'validate_user.php',
    //data: {usuario : $('#usuario-field').val(), password : $('#usuario-password').val() },
    data: {'usuario' : 'prueba', 'password' : 'pruebapass' },
    dataType : 'json',
    success : function(data){
    $('#waiting').hide(500);
    $('#message').removeClass().addClass((data.error === true) ? 'error' : 'success')
    .text(data.msg).show(500);
    if (data.error === true) 
    $('#login-box').show(500);
    },
    error : function(XMLHttpRequest, textStatus, errorThrown) {
    alert(errorThrown);
    $('#waiting').hide(500);
    $('#message').removeClass().addClass('error')
    .text('There was an error.').show(500);
    $('#login-box').show(500);
    }
    });
     
    return false;
    });
    });
    Can someone help me out, please? I tried to read on Google and resolve this yesterday, I am still reading today, but now I feel I need some assistance, don't know where exactly is the syntax error, hope it is something simple and some experienced user can help me with this. Regards.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    38
    Rep Power
    3
    Originally Posted by jaimitoc30
    Hi, I am starting to learn jQuery, AJAX and JSON. I am trying to pass a variable to a PHP script called validate_user.php using the jQuery, AJAX, JSON technique. I keep getting the error SyntaxError: JSON.parse: unexpected character. I have tried a lot of ways to make it work.. and this is the code for the ajaxSubmit.js

    Code:
    $(document).ready(function(){
    $('#loginbutton').click(function() {
    $('#waiting').show(100);
    $('#login-box').hide(0);
    $('#message').hide(0);
    
    $.ajax({
    type: 'POST',
    url: 'validate_user.php',
    //data: {usuario : $('#usuario-field').val(), password : $('#usuario-password').val() },
    data: {'usuario' : 'prueba', 'password' : 'pruebapass' },
    dataType : 'json',
    success : function(data){
    $('#waiting').hide(500);
    $('#message').removeClass().addClass((data.error === true) ? 'error' : 'success')
    .text(data.msg).show(500);
    if (data.error === true) 
    $('#login-box').show(500);
    },
    error : function(XMLHttpRequest, textStatus, errorThrown) {
    alert(errorThrown);
    $('#waiting').hide(500);
    $('#message').removeClass().addClass('error')
    .text('There was an error.').show(500);
    $('#login-box').show(500);
    }
    });
     
    return false;
    });
    });
    Can someone help me out, please? I tried to read on Google and resolve this yesterday, I am still reading today, but now I feel I need some assistance, don't know where exactly is the syntax error, hope it is something simple and some experienced user can help me with this. Regards.
    If someone is interested what was the issue, actually it was an issue with the validate_user.php file. I ran that on my browser and the script had something incorrect, so that was causing the issue

IMN logo majestic logo threadwatch logo seochat tools logo