Welcome Guest, Not a member yet? Register   Sign In
JQuery $.post() and CI inquiry
#1

[eluser]stevefink[/eluser]
Hi all,

I have a simple javascript file being loaded externally that has the following code:

-- snip --

$(document).ready(function() {

$('#pendingUsers').load('index.php/meduser/check_pending_users',false, function() {
$('#pendingUsers a').click(function() {
$.post('index.php/meduser/pull_user_information', {id: $(this).attr('rel')}
);
});
});

setInterval(function() {
$('#pendingUsers').load('index.php/meduser/check_pending_users');
}, 300000);

// initially hide the main content div until a pending user is clicked.

});

-- snip --

My issue here is I'm not sure how with CI to associate the $.post() with the div I want to populate the data back from the server with in a view. My view contains a <div id="main"></div> area where the results should be posted back.

My controller looks like this:

function pull_user_information()
{
$id = $this->input->post('id');
$data['query'] = $this->db_users->query('select * from tbl_signups
where ID="$id"'
);

$this->load->view('default/meduser_useraccordny_view', $data);
}

I'm trying to populate the rel of the anchor tag into $id and using that to query the database.

I can then pass that into the meduser_useraccordny_view, however I'm still not entirely sure how to populate the particular div.

Any assistance would be appreciated!
#2

[eluser]kucerar[/eluser]
[quote author="stevefink" date="1187051673"]Hi all,

I have a simple javascript file being loaded externally that has the following code:

Code:
$(document).ready(function() {
        
    $('#pendingUsers').load('index.php/meduser/check_pending_users',false, function() {
     $('#pendingUsers a').click(function() {
         $.post('index.php/meduser/pull_user_information', {id: $(this).attr('rel')}    
         );
     });        
    });

    setInterval(function() {
        $('#pendingUsers').load('index.php/meduser/check_pending_users');
    }, 300000);

    // initially hide the main content div until a pending user is clicked.
    
});

My issue here is I'm not sure how with CI to associate the $.post() with the div I want to populate the data back from the server with in a view. My view contains a <div id="main"></div> area where the results should be posted back.

...[/quote]

Code:
$('#pendingUsers').load('index.php/meduser/check_pending_users',false, function() {
     $('#pendingUsers a').click(function() {
         $.post('index.php/meduser/pull_user_information', {id: $(this).attr('rel')},
          function(data){
            $('main').html("Data Loaded: " + data);
          }  
         );
     });        
    });

Wouldn't that callback load the DIV?

-R
#3

[eluser]stevefink[/eluser]
Well, I've tried debugging, and in this case:

$('#pendingUsers a').click(function() {
$.post('index.php/meduser/pull_user_information', {id: $(this).attr('rel')},
function(data) {
$('#main').html(data);
alert("Data: " + data);
}
);
});

data appears to be empty. No idea what the problem is though.
#4

[eluser]座頭市[/eluser]
I think you have a quoting problem: single quotes will not parse variables passed to them - the database is looking for the value $id in the ID column, of course, does not exist and thus causing the empty data set. Try reversing the single and double quote.
Code:
$data[’query’] = $this->db_users->query("SELECT * FROM tbl_signups
WHERE ID='$id'");
#5

[eluser]stevefink[/eluser]
Yes, rather embarrasing that after hours of debugging, that was my problem.

I'll be more cautious in the future, thanks again.




Theme © iAndrew 2016 - Forum software by © MyBB