Login with jQuery AJAX is not working

Sarvap Praharanayuthan
function do_login()
{
$('.loginsubmit').click(function(e)
{
    var datum=$('.loginform').serialize();
    $.ajax({
        type: "POST",
        url: "login",
        data: datum,
        contentType: "application/json; charset=utf-8",
        dataType:"json",
        success: function(data)
        {
            if(data.prop=="false")
            {
                $('p#login-error-notif').text(data.error);
            }
            else if(data.prop=="true")
            {
                $('#logindrp span').text("Welcome "+data.name);
            }
        }
    });            
});
} //closing do_login function

This is the function called when user click on the Login the button. The error I see is the Uncaught reference error: 'prop' of null.

The code in the PHP page is

        if(isset($_POST['username']))
        {
         $username=$_POST['username']

...// proceed with checking the username and password

    if($check_login)
    {
    $return=array(prop=>"true", name=>$name, username=>$username);  
        echo json_encode($return);  
    }
            else
            {
            $return=array(prop=>"false", error=>"Invalid username/password.");  
        echo json_encode($return);
            }


        }

But I observed this part is not being executed. I mean the 'username' is not sent to the page. I checked it with adding the code setcookie("username", $username); inside it. The cookie is never created. What is the problem in my AJAX request?

Sarvap Praharanayuthan

It worked well after resolving the following errors:

  1. contentType: "application/json; charset=utf-8", Thank you marteljn.

  2. Enclosing the variables prop, error, username in single codes.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Ajax and jQuery call of $ajax url not working

분류에서Dev

jQuery $.ajax post to PHP in the same file not working

분류에서Dev

JQuery .click() not working on appended <tr> from ajax

분류에서Dev

retrieving images from server using ajax, jQuery. code not working

분류에서Dev

jquery ajax form validation not working with GET method codeigniter

분류에서Dev

XPages: Login not working?

분류에서Dev

Remote Login from the greeter not working

분류에서Dev

My PHP User Login is Not Working

분류에서Dev

The Enter button not working on Login page

분류에서Dev

wordpress json api and ajax login

분류에서Dev

Ajax links not working

분류에서Dev

Umbraco AJAX call not working

분류에서Dev

$.ajax not working in angularjs

분류에서Dev

$.ajax not working while working with fullcalendar js?

분류에서Dev

Ubuntu 18.04 keyboard and mouse not working at login screen

분류에서Dev

Cordova: login with facebook using javascript api not working

분류에서Dev

Sudo command not found (su login not working)

분류에서Dev

LDAP and PAM working for GUI login but not SSH

분류에서Dev

AJAX loading in HTML to a div not working

분류에서Dev

Ajax code dose not working properly

분류에서Dev

AJAX call to a PHP file not working

분류에서Dev

ajax GET not working with Header parameters

분류에서Dev

MVC Ajax alert not working properly

분류에서Dev

jquery .animate is not working

분류에서Dev

JQuery Parallax not working

분류에서Dev

JQuery not working on Joomla 3

분류에서Dev

jQuery .post() function not working

분류에서Dev

jquery post not working and no error

분류에서Dev

Jquery content slider not working