0

I'm trying to get data back from the database but I cannot figure out why I'm not getting any output. I'm using jQuery/AJAX:

$(document).ready(function(){
      $('#banktransfer_blz').blur( function(){
                    send_blz( $(this).val() );
            } );

    } );

function send_blz(str){
      $.post( "get_swift.php", 
          { sendBLZ: str }, 
          function(data){
            $('#banktransfer_bic').val( data.return_bic ).html();
          },
          "json");
    }

And here is the get_swift.php:

if (isset($_POST['sendBLZ'])){
$value = $_POST['sendBLZ']; 
}

$test = "test";

$swift = xtc_db_query("SELECT customers_id FROM customers WHERE customers_cid ='20002'"); 


echo json_encode( array( "return_bic" => $swift) ); 

I am connected to the database.

1
  • What's xtc_db_query? And don't you need to fetch the data? Commented Jan 30, 2014 at 11:24

3 Answers 3

2

Try this, You need to use xtc_db_fetch_array to fetch the customers_id from table

in get_swift.php:

 $swift = xtc_db_query("SELECT customers_id FROM customers WHERE customers_cid ='20002'");
 $row = xtc_db_fetch_array($swift);
 echo json_encode( array( "return_bic" => $row['customers_id']) );

Also,

 $('#banktransfer_bic').val( data.return_bic );

instead of

$('#banktransfer_bic').val( data.return_bic ).html();
Sign up to request clarification or add additional context in comments.

Comments

0

Try using Browser's developer tools and check XHR request. If it's ok, make sure the page from where you are going to fetch data is separately connected to database. You can check this by visiting this page directly from browser's URL and the output should be what you want through ajax.

also in your ajax code, try changing

$('#banktransfer_bic').val( data.return_bic ).html();

to

$('#banktransfer_bic').html( data.return_bic );

Comments

0

I am assuming you get the desired response when you calling the php file directly.

You are resetting the #banktransfer_bic html by doing $('#banktransfer_bic').html();

try to use: $('#banktransfer_bic').html(data.return_bic); instead

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.