Welcome Guest, Not a member yet? Register   Sign In
Codeigniter with Ajax
#11

[eluser]Joshi[/eluser]
It doesnt seem to be a javascript problem. I am using ajax to call the function. If i run the page that i call in Ajax, i am able to get the values. What happens is after fetching the data, i am unable to pass the values back to the text boxes. I hope i have missed something. Can u recheck my code assuming that i am calling the function in select option.
#12

[eluser]kkith[/eluser]
assuming you are calling the php function and it gets a response, you have this...

document.getElementById('bankNameForACH')[removed]=req.responseText;

but i don't think that's correct, shouldn't it be...
document.getElementById('bankNameForACH').value=req.responseText;
?
#13

[eluser]Joshi[/eluser]
U r right. The text is replaced in that. I have used innerHTML in the place of the value.Both value and innerHTML doesnt seems to work.
#14

[eluser]kkith[/eluser]
Add the alert call...and see if anything happens. If nothing happens then either the ajax call to the handler is making it, or the handler isn't making it back.
Code:
if (req.status == 200) {
     alert(req.responseText);
     document.getElementById('bankNameForACH').value=req.responseText;                                
}

[quote author="Joshi" date="1275327516"]U r right. The text is replaced in that. I have used innerHTML in the place of the value.Both value and innerHTML doesnt seems to work.[/quote]
#15

[eluser]Joshi[/eluser]
When i alert i get the following printed.What am i doing wrong in my code.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
&lt;html&gt;
&lt;head&gt;
&lt;link REL="SHORTCUT ICON" HREF="/images/fav.ico"&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;title&gt;Pay Securely to BBBB through Payment Helpdesk&lt;/title&gt;

&lt;/head&gt;
&lt;style type="text/css"&gt;
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-color: #626262;
}

.arial10 {
font-family: Arial;
font-size: 10px;
font-style: normal;
font-weight: normal;
color: #FF0000;
text-decoration: none;
}
.arial30 {
font-family: Arial;
font-size: 12px;
font-style: normal;
font-weight: normal;
text-decoration: none;
}
.arial20 {
font-family: Arial;
font-size: 18px;
font-style: normal;
font-weight: bold;
color: #000000;
text-decoration: none;
}
.arial20blue {
font-family: Arial;
font-size: 18px;
font-style: normal;
font-weight: bold;
color: #0A51A1;
text-decoration: none;
}
.tahoma25 {
font-family: tahoma;
font-size: 25px;
font-style: normal;
font-weight: bold;
#16

[eluser]Joshi[/eluser]
Please let me know what i am wrong or Is there any other way to do this ?
#17

[eluser]Joshi[/eluser]
Can anyone help me to solve this issue?
#18

[eluser]pickupman[/eluser]
If you are getting back html code from your alert(), you are sending a whole html page rather than just the input fields. I would presume that this is happening from $this->load->view(); Using jQuery:
Code:
$("select[name='accountNoForACH']").change(function(){
   $("input[name='bankNameForACH'],input[name='routingNoForACH']").val('');
   $.ajax({
       data:     $(this).parents("form").serialize(),
       dataType: 'json',
       url:      '&lt;?=site_url("controller/get_details");?&gt;',
       success:  function(data, statusText){
           if(data.response = '200'){
              $("input[name='bankNameForACH']").val(data.bankNameForACH);
              $("input[name='routingNoForACH']").val(data.routingNoForACH);
           }
       }        
   });
});

//In controller/get_details
function getDetails(){
  $accID = $this->input->post('bankNameForACH');
  $decryptAccount = encrypt($accID);
  $bankDetails = $this->accounts->getBankAccount($decryptAccount);
  $data = array();
  $data['response'] = '404';

  if($bankDetails){
    $data['bankNameForACH'] = $bankDetails->bankName;
    $data['routingNoForACH'] = $bankDetails->routingNo;
    $data['response'] = '200';
  }
  echo json_encode($data);
}

jQuery can make this very easy for you. It handles all of the XHR cross browser code for you. All that in 14 lines.
#19

[eluser]Joshi[/eluser]
Thanks for your response. I went through the code u have posted and find it simple when compared to Ajax. can you please let me know how to call the Javascript function in HTML.
#20

[eluser]pickupman[/eluser]
In your &lt;head&gt; tag, add a script tag pointing to your jquery source, then add
Code:
[removed]

jQuery(document).ready(function($){
$("select[name='accountNoForACH']").change(function(){
    $("input[name='bankNameForACH'],input[name='routingNoForACH']").val('');
    $.ajax({
        data:     $(this).parents("form").serialize(),
        dataType: 'json',
        url:      '&lt;?=site_url("controller/get_details");?&gt;',
        success:  function(data, statusText){
            if(data.response = '200'){
               $("input[name='bankNameForACH']").val(data.bankNameForACH);
               $("input[name='routingNoForACH']").val(data.routingNoForACH);
            }
        }        
    });
});
});
[removed]

The removed blocks would be your opening and closing script tags.




Theme © iAndrew 2016 - Forum software by © MyBB