Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
187
rated 0 times [  188] [ 1]  / answers: 1 / hits: 152148  / 11 Years ago, mon, september 16, 2013, 12:00:00

How do I return response from the controller back to the Jquery Javascript?



Javascript



$('.signinform').submit(function() { 
$(this).ajaxSubmit({
type : POST,
url: 'index.php/user/signin', // target element(s) to be updated with server response
cache : false,
success : onSuccessRegistered,
error: onFailRegistered
});
return false;
});


Data is returned null (blank)!



function onSuccessRegistered(data){
alert(data);
};


Controller -



public function signin() {
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode( $arr );
}

More From » php

 Answers
55
//do the edit in your javascript

$('.signinform').submit(function() {
$(this).ajaxSubmit({
type : POST,
//set the data type
dataType:'json',
url: 'index.php/user/signin', // target element(s) to be updated with server response
cache : false,
//check this in Firefox browser
success : function(response){ console.log(response); alert(response)},
error: onFailRegistered
});
return false;
});


//controller function

public function signin() {
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);

//add the header here
header('Content-Type: application/json');
echo json_encode( $arr );
}

[#75673] Friday, September 13, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brandt

Total Points: 43
Total Questions: 90
Total Answers: 111

Location: Aruba
Member since Fri, Jun 24, 2022
2 Years ago
brandt questions
Sun, Jul 4, 21, 00:00, 3 Years ago
Wed, Jun 30, 21, 00:00, 3 Years ago
Sat, Jan 23, 21, 00:00, 3 Years ago
Mon, Sep 21, 20, 00:00, 4 Years ago
;