Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
61
rated 0 times [  66] [ 5]  / answers: 1 / hits: 45879  / 11 Years ago, thu, december 5, 2013, 12:00:00

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!');
}

}

});

});

More From » php

 Answers
3
$.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.


[#73903] Tuesday, December 3, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
claudiofredye

Total Points: 583
Total Questions: 101
Total Answers: 115

Location: Sao Tome and Principe
Member since Wed, Dec 29, 2021
2 Years ago
;