Integrate php in jquery

This is jquery ajax method success message in which php code is integrated. If i am integrating php inside jquery . Below is the error in which i am getting. I am new to jquery not able to expect what is the error.

  • Uncaught ReferenceError: save_customer is not defined
  • Uncaught SyntaxError: Unexpected identifier

Here is the code:

function save_customer() {
  $('#save_customer_loader').show();
  // temporarily enable the billing fields (if disabled)
  /*if($('#different_address').is(':checked'))
     {
     $('.bill').attr('disabled', false);
     $('.bill').removeClass('disabled');
     }*/
  //send data to server
  form_data = $('#customer_info_form').serialize();

  $.post('<?php echo site_url('checkout / save_customer ') ?>', form_data, function(response) {
      if (typeof response != "object") // error
      {
        display_error('customer', '<?php echo lang('communication_error ');?>');
        return;
      }

      if (response.status == 'success') {

        <? php
        foreach($this - > go_cart - > contents() as $contents) {
          // check whether product polls are there and user has given poll feedback

          $result_row = $this - > db - > get_where('tryproduct_questionnaires', array('id' = > $contents['id'])) - > row();
          if ($result_row > 0) { ?>

            window.location = "<?php echo base_url();?>cart/tryproduct_questionnaires/<?php echo
 $contents['id'];?>"; <? php
          }
        } ?>
        //populate the information from ajax, so someone cannot use developer tools to edit the form after it's saved
        $('#customer_info_fields').html(response.view);
        // and update the summary to show proper tax information / discounts
        update_summary();
      } else if (response.status == 'error') {
        display_error('customer', response.error);
        $('#save_customer_loader').hide();
      }
    }, 'json');
}

For the syntax error, I would try separating that line of code:

$result_where = $this - > db - > get_where('tryproduct_questionnaires', array('id' = > $contents['id']));
$result_row = ($result_where ? $result_where - > row() : false);

That way you're verifying that the object exists before attempting to call it's row function.