Welcome Guest, Not a member yet? Register   Sign In
post callback in ajax?
#1

[eluser]newbie boy[/eluser]
i've done a select function in ajax, where if a user select on a certain username, it will display a certain info about him.

i used firebug console and it actually run perfectly by getting the right data for the post but my problem is there in no reponse or no display at all.

here's my code:
Code:
$("select#user").change(function(){
        
        var id = $(this).val();
        
        $.ajax({
            url: '../index.php/UserController/getUserInfo',
            data: 'id=' + id,
            type: 'POST',
            dataType: "json",
            success: function (data){
                if (data != null) {    
                
                    $.each(data, function() {

                       $("p#id").append(id);
                        
                    })
                    
                }
    
                else
                    if (data == null) {
                    
                    }
            },
            error: function(xhr, err, e){
                alert("Error: " + err);
            }
        }); // $.ajax()
        
    });

thanks guys.
#2

[eluser]TheFuzzy0ne[/eluser]
Please post thegetUserInfo method.
#3

[eluser]newbie boy[/eluser]
for my controller, i'm using the Doctrine ORM.

here's the code:
Code:
function getUserInfo(){
            
    $firstname = $this->input->post('firstname');
    
    $UserModel = Doctrine_Query::create()
        ->select('*')
        ->from('UserModel u')
        ->where('u.firstname = :firstname',array(':firstname' => $firstname))
        ->fetchArray();  
                
        $output = json_encode($UserModel);
        print_r($output);
            
        }

actually, there is a response but an array symbol just like this [].

thanks again guys.
#4

[eluser]slowgary[/eluser]
I'm just guessing but maybe the problem is that you're requesting the return data in a JSON format? Then you're passing it to jQuery's $.append(), which I believe expects HTML/text content as it's parameter.

I could be wrong though. Good luck.
#5

[eluser]newbie boy[/eluser]
this now works!

Code:
$("select#user").change(function(){
        
        var id = $(this).val();
        
        $.ajax({
            url: '../index.php/UserController/getUserInfo',
            data: 'id=' + id,
            type: 'POST',
            dataType: "json",
            success: function (data){
                if (data != null) {    
  
                    $("p#id").append(id);
  
                }
    
                else
                    if (data == null) {
                    
                    }
            },
            error: function(xhr, err, e){
                alert("Error: " + err);
            }
        }); // $.ajax()
        
    });

but...
my problem now is how will i add more variable/objects to display from a user's file?
and at the same time whenever a user selects one username to another username it will not add to the current display?




Theme © iAndrew 2016 - Forum software by © MyBB