电话号码不是通过Ajax选择受益人的下拉列表,它给出了以下错误
http://localhost//sbmpunjab/website_control/admin_form/phone_ajax_report.php?benficiary=507
SyntaxError:JSON.parse:JSON数据第2行第1列的意外字符
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f
; font-size: x-large;'>( ! )</span> Notice: Undefined index: beneficiary in C:\wamp\www\sbmpunjab\website_control
\admin_form\phone_ajax_report.php on line <i>4</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align
='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left'
bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0015</td><td bgcolor
='#eeeeec' align='right'>136064</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp\www\sbmpunjab
\website_control\admin_form\phone_ajax_report.php' bgcolor='#eeeeec'>..\phone_ajax_report.php<b>:</b
>0</td></tr>
</table></font>
{"phone_number":"<select name=\"phone_number\"><option value=\"\">Select phone number<\/option>"}
码
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
function getXMLHTTP() { //fuction to return the xml http object
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}
function getState(districtId) {
var strURL="http://localhost//sbmpunjab/website_control/admin_form/constituency_report.php?district="+districtId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
var returnedData = JSON.parse(req.responseText);
$('#Blockdiv').html(returnedData.block);
//document.getElementById('GramPanchdiv').innerHTML='<select name="grampanch"><option>Select Gram Panchayat</option></select>';
} else {
alert("Problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
function getCity(districtId,blockId) {
var
strURL="http://localhost//sbmpunjab/website_control/admin_form/mis_village_report.php?district="+districtId+"&block="+blockId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
var returnedData = JSON.parse(req.responseText);
$('#GramPanchdiv').html(returnedData.GramPanch);
//$('#GramPanchdiv select[name=grampanch]').html(returnedData.GramPanch);
//document.getElementById('Beneficiarydiv').innerHTML='<select name="beneficiary"><option>Select Beneficiary</option></select>';
} else {
alert("Problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
function getBeneficiary(blockId,villageId) {
var strURL="http://localhost//sbmpunjab/website_control/admin_form/beneficiary_ajax_report.php?block="+blockId+"&village="+villageId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
var returnedData = JSON.parse(req.responseText);
$('#Beneficiarydiv').html(returnedData.beneficiary_name);
//$('#Beneficiarydiv select[name=beneficiary_name]').html(returnedData.beneficiary_name);
} else {
alert("Problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
function getPhno(benId) {
var
strURL="http://localhost//sbmpunjab/website_control/admin_form/phone_ajax_report.php?benficiary="+benId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
var returnedData = JSON.parse(req.responseText);
$('#PhoneNodiv select[name=phone_number]').html(returnedData.phone_number);
} else {
alert("Problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
</script>
形式
<form method="POST" name="Teleform" id="Teleform" action="<?=DIR_WS_SITE_CONTROL?>index.php?Page=<?=$Page?>&Section=<?=$Section?>&Target=AddTele&TeleID=<?=$TeleID?>" enctype="multipart/form-data" onsubmit="return ValidateForm(this);">
<table border="0" cellpadding="3" cellspacing="1" width="100%" class="InsideTable">
<tr>
<td align="left" class="InsideLeftTd"><b>Name of TeleCaller</b></td>
<td align="left" class="InsideRightTd">
<select name="tele_caller_id" id="tele_caller_id" title="Please select telecaller name.">
<option>Select Telecaller name</option>
<?
$DefaultCategory = isset($_POST['id'])?MyStripSlashes($_POST['id']):(isset($CurrentTele->tele_caller_id)?MyStripSlashes($CurrentTele->tele_caller_id):"");
$CategoryObj = new DataTable(TABLE_TELE_CALLER_LIST);
$CategoryObj->TableSelectAll("","id ASC");
while ($CurrentCategory1 = $CategoryObj->GetObjectFromRecord())
{
?>
<option value="<?=$CurrentCategory1->id?>" <?=$DefaultCategory==$CurrentCategory1->id?"selected":""?>><?=$CurrentCategory1->tele_caller_name?></option>
<?
}
?>
</select>
</td>
</tr>
<tr>
<td width="20%" class="InsideLeftTd"><b>District</b></td>
<td class="InsideRightTd">
<select name="district" id="district" title="Please select district." onChange="getState(this.value)">
<?
$DefaultDistrict = isset($_POST['district'])?MyStripSlashes($_POST['district']):(isset($CurrentTele->district_id)?MyStripSlashes($CurrentTele->district_id):DEFINE_DEFAULT_DISTRICT);
$DistrictObj = new DataTable(TABLE_DISTRICT);
$DistrictObj->TableSelectAll("","district ASC");
while ($CurrentDistrict = $DistrictObj->GetObjectFromRecord())
{
?>
<option value="<?=$CurrentDistrict->id?>" <?=$DefaultDistrict==$CurrentDistrict->id?"selected":""?>><?=$CurrentDistrict->district?></option>
<?
}
?>
</select>
</td>
</tr>
<?php
if(isset($CurrentTele->district_id) && $CurrentTele->district_id!='0'){
$BlockObj = new DataTable(TABLE_BLOCKS);
$BlockObj ->Where ="district_id='".$CurrentTele->district_id."'";
$BlockObj->TableSelectAll();
}
?>
<tr>
<td width="20%" class="InsideLeftTd"><b>Block</b></td>
<td class="InsideRightTd">
<div id="Blockdiv">
<? if(isset($CurrentTele->district_id) && $CurrentTele->district_id!='0'){?>
<select name="block" onchange="getCity('<?php echo $CurrentTele->district_id; ?>', this.value)" >
<?while ($CurrentBlock = $BlockObj->GetObjectFromRecord())
{
?>
<option value="<?=$CurrentBlock->id?>"<?=$CurrentBlock->id==$CurrentTele->block_id ? "selected":""?>> <?=$CurrentBlock->block_name ?></option>
<?
}
?>
</select>
<?}?>
<option>Select Block</option>
</div>
</td>
</tr>
<? if(isset($CurrentTele->district_id) && $CurrentTele->district_id!='0'){
$GramPanchObj = new DataTable(TABLE_GRAM_PANCHAYAT);
$GramPanchObj ->Where ="block_id='".$CurrentTele->block_id."'";
$GramPanchObj->TableSelectAll();
}
?>
<tr>
<td width="20%" class="InsideLeftTd"><b>Gram Panchayat</b></td>
<td class="InsideRightTd">
<div id="GramPanchdiv">
<? if(isset($CurrentTele->district_id) && $CurrentTele->district_id!='0'){?>
<select name="grampanch" onchange="getBeneficiary('<?php echo $CurrentTele->block_id; ?>', this.value)" >
<?while ($CurrentGramPanch = $GramPanchObj->GetObjectFromRecord())
{
?>
<option value="<?=$CurrentGramPanch->id?>"<?=$CurrentGramPanch->id==$CurrentTele->village_id ? "selected":""?>> <?=$CurrentGramPanch->village_name ?></option>
<?
}?>
</select>
<?}?>
<option>Select Gram Panchayat</option>
</div>
</td>
</tr>
<? if(isset($CurrentTele->village_id) && $CurrentTele->village_id!='0'){
$BeneObj = new DataTable(TABLE_BENEFICARY);
$BeneObj ->Where ="village_id='".$CurrentTele->village_id."'";
$BeneObj->TableSelectAll();
}
?>
<tr>
<td width="20%" class="InsideLeftTd"><b>Name of Beneficiary</b></td>
<td class="InsideRightTd">
<div id="Beneficiarydiv">
<? if(isset($CurrentTele->beneficiary_name) && $CurrentTele->beneficiary_name!='0'){?>
<select name="beneficiary_name" onchange="getPhno(this.value)">
<?while ($CurrentBene = $BeneObj->GetObjectFromRecord())
{
?>
<option value="<?=$CurrentBene->beneficiary_name?>"<?=$CurrentBene->beneficiary_name==$CurrentTele->beneficiary_name ? "selected":""?>> <?=$CurrentBene->beneficiary_name ?></option>
<?
}?>
</select>
<?}?>
<option>Select Beneficiary Name</option>
</div>
</td>
</tr>
<? if(isset($CurrentTele->village_id) && $CurrentTele->village_id!='0'){
$PhoneObj = new DataTable(TABLE_BENEFICARY);
$PhoneObj ->Where ="village_id='".$CurrentTele->village_id."'";
$PhoneObj->TableSelectAll();
}
?>
<tr>
<td width="20%" class="InsideLeftTd"><b>Phone No.</b></td>
<td class="InsideRightTd">
<div id="PhoneNodiv">
<select name="phone_number" >
<? if(isset($CurrentTele->phone_number) && $CurrentTele->phone_number!='0'){
while ($CurrentBenePh = $PhoneObj->GetObjectFromRecord())
{
?>
<option value="<?=$CurrentBenePh->phone_number?>"<?=$CurrentBenePh->phone_number==$CurrentTele->phone_number ? "selected":""?>> <?=$CurrentBenePh->phone_number ?></option>
<?
}
}?>
<option>Select Phone No</option>
</select>
</div>
</td>
</tr>
phone_ajax_report.php
<?php
$beneficiary=intval($_GET['beneficiary']);
$con = mysqli_connect('localhost', 'root', '','sbmpunjab');
if (!$con) {
die('Could not connect: ' . mysqli_error());
}
//mysqli_select_db($con,'sbmpunjab');
$query="SELECT * FROM zsk_beneficiary WHERE id='$beneficiary'";
$result=mysqli_query($con,$query);
$phone = '<select name="phone_number"><option value="">Select phone number</option>';
while ($row = mysqli_fetch_array($result)){
$phone .= "<option value='".$row['phone_number']."'>".$row['phone_number']."</option></select>";
}
$returnArray = array();
$returnArray['phone_number'] = $phone;
echo json_encode($returnArray);
exit;
?>