I need to upload websql table to the server using ajax. when I use indexed array or simple variable code works fine. I cant figure out what problem is? plz help me. thanks in advance... here is javascript:
function upload()
{
var db = cropsap.webdb.db;
db.transaction(function (tx) {
tx.executeSql('SELECT * from survey', [],function(tx, results) {
var data = "";
var survey=[];
for(var i=0; i < results.rows.length; i++) {
var row = results.rows.item(i);
var result = [];
for(var key in row)
{
result[key] = row[key];
}
survey.push(result);
}
//alert(survey[0]['srno']);//here i get output
var url = "";
url = document.getElementById("url").value;
$.ajax({
type: "POST",
url: url,
async: true,
data: { "data": JSON.stringify(survey) },
error: function () { alert("error occured");},
success: function (data) {
alert("sucess");
alert(data);
}
});
});
});
}
php code:
<?php
$survey= json_decode(stripslashes($_POST['data']));
$len = sizeof($crop_insect_survey_details);
print(" len: ".$len);
for($i=0;$i<$len;$i++)
{
$srno = $crop_insect_survey_details[$i]['srno'];//here cant get output
$name = $crop_insect_survey_details[$i]['name'];
print("srno:".$srno);
print("name:".$name);
}
?>