How to get the ajax response from success and assign it in a variable using jQuery?

Jerielle

Hello guys I have a problem in getting the response from my ajax. If I display it in the console. I can view it. But How do I assign it in a variable?

Here's what I have. In my PHP code I have this

public function checkPassword($password){

            $username = $this->session->userdata('username');
            $validate = $this->members_model->checkPassword($password,$username);

            echo $validate;

}

In my jquery I have this

$('#existing').on('keyup',function(){

            var id = '<?php echo $this->session->userdata("user_id"); ?>';
            var password_url = '<?php echo site_url("member/checkPassword/' +id+ '"); ?>';

            $.ajax({
                type: 'POST',
                url: password_url,
                data: '',
                dataType: 'json',
                success: function(response){

                var g = response;
                if(g == 1){
                    $('#existing_info').html('Password is VALID'); //Doesn't display the VALID if the response is 1. Why?
                }else{
                    $('#existing_info').html('Password is INVALID!');
                }

                }

            });

        });
Prateek
$.ajax({
        type: 'POST',
        url: password_url,
        data: '',
        dataType: 'json',
        success: function(response){
           var k=response;

           if(k.indexOf("1") != -1)
             $('#existing_info').html('Password is VALID');
           else
              $('#existing_info').html('Password is INVALID!');
        }
    });

response is in response variable of success function.

indexof returns the index within the calling String object of the first occurrence of the specified value, starting the search at fromIndex, returns -1 if the value is not found.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get the ajax response from success and assign it in a variable using jQuery?

From Dev

Get Specfic response from MySql in jQuery AJAX Success

From Dev

How to get response text from ajax callback in a variable using ExtJS

From Dev

How to get the response text from an AJAX request using jQuery

From Dev

get a variable from php using ajax/jquery

From Dev

How to get data from database and assign it to inputs values using PHP and jQuery AJAX

From Dev

how do i get a response from a jquery ajax request

From Dev

JS - Can not assign response from AJAX as custom variable

From Dev

how to get JSON response from servlet to jsp page by using ajax

From Dev

how to get response from node server using ajax method in html

From Dev

How to get response from PHP file as an array using Ajax?

From Dev

JQuery Ajax: assign response to two variables using a single request

From Dev

Using variable from ajax response as json

From Dev

AJAX/Jquery - Get response from php file

From Dev

jQuery get response from ajax function

From Dev

Bind dropdownlist from jquery ajax call success function using angularjs

From Dev

how to read javascript variable from ajax success callback function

From Dev

how to read javascript variable from ajax success callback function

From Dev

How to get the response title from the "jqXHR" object using jQuery?

From Dev

How can I get in 'clicked' element in jquery ajax success callback

From Dev

How to select a variable from an AJAX response

From Dev

Success/Fail in AJAX response from Rails

From Java

How to get the value of Ajax response in jQuery

From Dev

How to pass a variable from Jquery to PHP using Ajax?

From Dev

How to LOOP inside the Array returned from jQuery Ajax Success?

From Dev

How to LOOP inside the Array returned from jQuery Ajax Success?

From Dev

How to assign a $http.get response to a variable AngularJS

From Dev

How to get attr of element from ajax success result of codeigniter calendar?

From Dev

How to pass and use a success/failure response with AJAX

Related Related

  1. 1

    How to get the ajax response from success and assign it in a variable using jQuery?

  2. 2

    Get Specfic response from MySql in jQuery AJAX Success

  3. 3

    How to get response text from ajax callback in a variable using ExtJS

  4. 4

    How to get the response text from an AJAX request using jQuery

  5. 5

    get a variable from php using ajax/jquery

  6. 6

    How to get data from database and assign it to inputs values using PHP and jQuery AJAX

  7. 7

    how do i get a response from a jquery ajax request

  8. 8

    JS - Can not assign response from AJAX as custom variable

  9. 9

    how to get JSON response from servlet to jsp page by using ajax

  10. 10

    how to get response from node server using ajax method in html

  11. 11

    How to get response from PHP file as an array using Ajax?

  12. 12

    JQuery Ajax: assign response to two variables using a single request

  13. 13

    Using variable from ajax response as json

  14. 14

    AJAX/Jquery - Get response from php file

  15. 15

    jQuery get response from ajax function

  16. 16

    Bind dropdownlist from jquery ajax call success function using angularjs

  17. 17

    how to read javascript variable from ajax success callback function

  18. 18

    how to read javascript variable from ajax success callback function

  19. 19

    How to get the response title from the "jqXHR" object using jQuery?

  20. 20

    How can I get in 'clicked' element in jquery ajax success callback

  21. 21

    How to select a variable from an AJAX response

  22. 22

    Success/Fail in AJAX response from Rails

  23. 23

    How to get the value of Ajax response in jQuery

  24. 24

    How to pass a variable from Jquery to PHP using Ajax?

  25. 25

    How to LOOP inside the Array returned from jQuery Ajax Success?

  26. 26

    How to LOOP inside the Array returned from jQuery Ajax Success?

  27. 27

    How to assign a $http.get response to a variable AngularJS

  28. 28

    How to get attr of element from ajax success result of codeigniter calendar?

  29. 29

    How to pass and use a success/failure response with AJAX

HotTag

Archive