php - AJAX isn't returning any data -
still new ajax. sense i'm not grasping completely. want submit partial info server, perform sql query , homecoming results. have far:
jquery
j$('select[name=agent_name]').change(function(event) { event.preventdefault(); var agentid = j$(this).val(); post_data = {'agent_id':agentid}; console.log("about post info server"); j$.post('../include/booking_modify.php', post_data, function(response){ if(response.type == 'agdepcd'){ output = response.text; console.log(output); } if(response.type == 'error'){ output = response.text; console.log(output); } }, 'json'); });
php
<?php session_start(); require("../include/conn.php"); dbopen(); //check $_post vars set, exit if missing if(!isset($_post["agent_id"])) { $output = json_encode(array('type'=>'error', 'text' => 'nothing selected!')); die($output); } $stmt = $conn->prepare("select agdepcd agents agentid = ?"); $stmt->bind_param('i', $_post["agent_id"]); // bind variables parameter $stmt->execute(); $row = $result->fetch_assoc(); $agdepcd = $row['agdepcd']; $stmt->close(); $output = json_encode(array('type'=>'agdepcd', 'text' => $agdepcd)); die($output); ?>
i checked create sure: file path correct. var agentid = j$(this).val(); grabs value, manually entered sql query phpmyadmin ensure retrieving results. can't seem homecoming server. i'm not sure possible. please help!
normally echo , exit, short , faster. in beforehand entering response, console.log
, check out if homecoming any. if doesn't check php code, there other error encoding output. seek it.
<?php session_start(); require("../include/conn.php"); dbopen(); //check $_post vars set, exit if missing if(!isset($_post["agent_id"])) { echo json_encode(array('type'=>'error', 'text' => 'nothing selected!')); exit; } $stmt = $conn->prepare("select agdepcd agents agentid = ?"); $stmt->bind_param('i', $_post["agent_id"]); // bind variables parameter $stmt->execute(); $row = $result->fetch_assoc(); $agdepcd = $row['agdepcd']; $stmt->close(); echo json_encode(array('type'=>'agdepcd', 'text' => $agdepcd)); exit; ?>
php jquery mysql ajax json
No comments:
Post a Comment