i've got simple jquery script isn't behaving correctly. doing wrong? idea user enters value textbox , clicks button. jquery uses post send value php file. php file runs simple sql query , gives response. jquery .load used refresh div containing original php.
using chrome's tools, i've noticed response post perfect. however, gets overwritten no data.
jquery:
$("#gotest").click(function() { var customer = $("#customer").val(); if (customer == '') { $('#alert_formula_save_failed').show(); } else { $.post("../assets/forms/formulations/set_session.php", { customer: customer, }, function(data) { $('#alert_formula_save_success').show(); $('#dynamic').load('../assets/forms/formulations/set_session.php'); $('#alert_formula_save_failed').hide(); settimeout(function() { $('#alert_formula_save_success').fadeout('fast'); }, 3000); }); } }); php:
<?php $customer = null; $customer = 'test' ; $customer2 = $_post['customer'] ; .. db connection bits ; try { $pdo = new pdo( "mysql:host=".$host.";"."dbname=".$dbname, $user, $pass); } catch(pdoexception $e) { die($e->getmessage()); } $pdo->setattribute(pdo::attr_errmode, pdo::errmode_exception); $sql = "select * db_customers customer = '$customer' "; $stmt = $pdo->prepare($sql); $stmt->execute(array($id)); $data = $stmt->fetch(pdo::fetch_assoc); $pdo = null; $iscurrent = $data['iscurrent']; echo '<br>' ; echo 'response 1-' ; echo $iscurrent; echo '<br>' ; echo 'response 2-' ; echo $customer2 ; ?> html:
<form id="testform" name="testform" method="post"> <button type="button" name="gotest" id="gotest" class="btn btn-info"> <i class="fa fa-frown-o"></i> set session </button> the idea being 'response 1' echoes predefined value. response 2 should echo out whatever typed text input box.. overwrites everything.
the "issue" line:
$('#dynamic').load('../assets/forms/formulations/set_session.php'); it uses default.
try using in place:
$('#dynamic').html(data);
Comments
Post a Comment