Search code examples
jqueryajaxrhomobile

getting Type Error in Ajax call


In my rhomobile application am using ajax call, when I made a request am getting Type Error in console am not getting the where I did mistake.

Here is my code

$( document ).ready(function() {
    $("#btn_login").on("click",function(){
        alert("hi");
        var username = $('#txt_username').val();
        var password = $('#txt_password').val();
        alert(username+","+password)
        $.ajax({
            url: 'app/Login/login_request',
            dataType: 'json',
            data: {username: $('#txt_username'),
                    password: $('#txt_password')
                    },
            type: 'GET'
        }).done(function(data){
            alert(data);
        });
    });
});

Please help me.


Solution

  • Try this.

    <input type="text" id="txt_username">
    <input type="password" id="txt_password">
    <input id="btn_login" type="submit">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $("#btn_login").on("click",function(){
            //alert("hi");
            var username = $('#txt_username').val();
            var password = $('#txt_password').val();
            //alert(username+","+password)
            $.ajax({
                url: 'app/Login/login_request',
                dataType: 'json',
                data: {username: username,password: password},
                type: 'GET'
            }).done(function(data){
                alert(data);
            });
        });
    });
    </script>