Click here to Skip to main content
15,897,334 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends,
I face to this problem please help me, the array which I return from php file I can not access its element in my ajax code, can you help me plz,
its my php code

<?php
require_once("connection.php");
global $conn;

if (isset($_POST['expGoodsName'])) {

$expCheckSNo=$_POST['expCheckSNo'];
$goodsName=$_POST['expGoodsName'];

$goodsNamequery= mysqli_query($conn,"SELECT S.Quantity, S.Unit, S.UnitPrice FROM tblstock S
INNER JOIN tblimportcheck imp USING(ImpSNo)
INNER JOIN tblexportcheck exp USING(ImpSNo)
WHERE exp.ExpSNO =$expCheckSNo AND S.GoodsName='$goodsName' ");

$rows=mysqli_fetch_assoc($goodsNamequery);

$qty=$rows['Quantity'];
$Unit=$rows['Unit'];
$UnitPrice=$rows['UnitPrice'];

$myArr = array($qty,$Unit, $UnitPrice);

$myJSON = json_encode($myArr);

echo $myJSON;

}
?>


here is ajax code:
$("#expGoodsName").change(function getQuantity(argument) {
sendImportCheck();
});

function sendImportCheck()
{
var XMLHttp;
if (window.XMLHttpRequest) {
// code for modern browsers
XMLHttp = new XMLHttpRequest();
}else {
// code for old IE browsers
XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
}

var expCheckSNo=$("#expCheckSNo").val();
var expGoodsName=$("#expGoodsName").val();

XMLHttp.onreadystatechange=function()
{
if(XMLHttp.status==200 && XMLHttp.readyState==4) {

var myresult= JSON.parse(XMLHttp.responseText);
alert(myresult[0]);//it should display first element

}
}
XMLHttp.open("POST","ExpCheckEdit.php",true);
XMLHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
XMLHttp.send("expCheckSNo="+expCheckSNo+"&expGoodsName="+expGoodsName);
}

What I have tried:

I tried a lot in google but nothing changed
Posted
Updated 20-Nov-18 20:25pm

1 solution

Start by using the debugger and looking at exactly what is being transfered and parsed - you need to work out if the problem is in your data, the conversion to JSON, or the conversion from JSON before you can begin to work out why.

So use the debugger, and look at what is happening at each stage, and try to identify exactly what "non-whitespace character" is being complained about, and where it came from.
You can't even begin to fix the problem until you know that.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900