Welcome Guest, Not a member yet? Register   Sign In
BugZ with ajax and jquery
#1

[eluser]1mr3yn[/eluser]
hey guyz.,. I encountering a problem with my new project which uses codeigniter, ajax and jquery.,.

I have a list of clients from a loop., and everytime a user clicked one client a dialog form will show with the details of the selected clients. and that details is from the database, my codes only works on the first list.,

the loop;
Code:
//start foreach
     <a href="" class="client_details">
            &lt;input type="hidden" value="&lt;?=$code?&gt;" class="hidden_client"/&gt;
               &lt;?=$member_name; ?&gt;
     </a>
   //end foreach

================================
the script:
Code:
$('.client_details').click(function(e) {
    e.preventDefault();
    $('#dialog').dialog('open');
    var  client = $('.hidden_client').val();
    $('.box').load("&lt;?= base_url().'controller/method' ?&gt;",{code: client});    
       return false;                  
   });

<*******************************>
the Controller
Code:
$cid = $_POST['code'];
  $this->db->where('code = ', $cid);
  $query = $this->db->get('table');
       $result = $query->result();
       foreach( $result as $field ) {
          //variables
       }
      $this->load->view('client_details',$data);

+++++++++++++++++++++++++++++++++++
Everytime I click any of the list., I always got the detail of the first list.
Thanks!!!
#2

[eluser]Thorpe Obazee[/eluser]
one comment. did not read thoroughly. why use,

Code:
var  client = $('.hidden_client').val();

when you have

Code:
&lt;input type="hidden" value="&lt;?=$code?&gt;" id="hidden_client"/&gt;
#3

[eluser]1mr3yn[/eluser]
because I need to pass the value of that hidden input, to the controller., and then retrieve all the data from the database.,
#4

[eluser]Thorpe Obazee[/eluser]
.hidden_client is a selector for a CSS class
#hidden_client is a selector for a CSS id

EDIT: you changed your code. good thing I quoted it. or else I'd look stupid.
#5

[eluser]Doosje[/eluser]
Code:
$('.client_details').click(function(e) {
    e.preventDefault();
    $('#dialog').dialog('open');
    var  client = $('.hidden_client').val();
    $('.box').load("&lt;?= base_url().'controller/method' ?&gt;",{code: client});    
       return false;                  
   });
Code:
var  client = $('.hidden_client').val(); //
Shouldn't that be:
Code:
var  client = $(this).val();
#6

[eluser]Thorpe Obazee[/eluser]
[quote author="Doosje" date="1245676638"]
Code:
$('.client_details').click(function(e) {
    e.preventDefault();
    $('#dialog').dialog('open');
    var  client = $('.hidden_client').val();
    $('.box').load("&lt;?= base_url().'controller/method' ?&gt;",{code: client});    
       return false;                  
   });
Code:
var  client = $('.hidden_client').val(); //
Shouldn't that be:
Code:
var  client = $(this).val();
[/quote]

I don't think that should work.

He should reference the hidden input if he is going to get it's value. Right now he is referencing the link which I think has an empty val().
#7

[eluser]1mr3yn[/eluser]
how to convert the script code into $.post not $().load.,
I really a newbie in ajax., Sorry..
#8

[eluser]Doosje[/eluser]
Your right bargainph i didn't read it correct

r3yn, can you give it try with this ?
Code:
$('.client_details').click(function(e) {
    e.preventDefault();
    $('#dialog').dialog('open');
    var  client = $('input.hidden_client',this).val();
    $('.box').load("&lt;?= base_url().'controller/method' ?&gt;",{code: client});    
       return false;                  
   });
#9

[eluser]Thorpe Obazee[/eluser]
[quote author="r3yn" date="1245677492"]how to convert the script code into $.post not $().load.,
I really a newbie in ajax., Sorry..[/quote]

Why do you need to change?
#10

[eluser]1mr3yn[/eluser]
Wow thanks a lot Doosje.,
it really works.,.
but How about,. same process but I want to used $.post instead of $().load.,. because $().load is a waste of page..




Theme © iAndrew 2016 - Forum software by © MyBB