Cant pass javascript varriable to php -


 <script> function getimgdata(chartcontainer) {     var chartarea = chartcontainer.getelementsbytagname('svg')[0].parentnode;     var svg = chartarea.innerhtml;     var doc = chartcontainer.ownerdocument;     var canvas = doc.createelement('canvas');     canvas.setattribute('width', chartarea.offsetwidth);     canvas.setattribute('height', chartarea.offsetheight);     canvas.setattribute(         'style',         'position: absolute; ' +         'top: ' + (-chartarea.offsetheight * 2) + 'px;' +         'left: ' + (-chartarea.offsetwidth * 2) + 'px;');     doc.body.appendchild(canvas);      canvg(canvas, svg);     var imgdata = canvas.todataurl('image/png');     canvas.parentnode.removechild(canvas);     return imgdata; }  function saveasimg(chartcontainer) {     var imgdata = getimgdata(chartcontainer);      // replacing mime-type force browser trigger download     // rather displaying image in browser window.     // window.location = imgdata.replace('image/png', 'image/octet-stream'); }  function toimg(chartcontainer) {      var doc = chartcontainer.ownerdocument;     var img = doc.createelement('img');     img.src = getimgdata(chartcontainer);     var test = getimgdata(chartcontainer);     $.ajax({         type: 'post',         url: "test.php",         data: "test" + test,         success: function (data) {         console.log(test);         }     }); }  google.load('visualization', '1', {packages:['corechart', 'treemap', 'geochart']}); google.setonloadcallback(drawchart);  function drawchart() { // pie chart     var data = new google.visualization.datatable();     data.addcolumn('string', 'task');     data.addcolumn('number', 'hours per day');     data.addrows(5);     data.setvalue(0, 0, 'work');     data.setvalue(0, 1, 11);     data.setvalue(1, 0, 'eat');     data.setvalue(1, 1, 2);     data.setvalue(2, 0, 'commute');     data.setvalue(2, 1, 2);     data.setvalue(3, 0, 'watch tv');     data.setvalue(3, 1, 2);     data.setvalue(4, 0, 'sleep');     data.setvalue(4, 1, 7);      var chart = new google.visualization.piechart(document.getelementbyid('pie_div'));       chart.draw(data, {width: 450, height: 300, title: 'my daily activities'});     toimg(document.getelementbyid('pie_div')); }   </script> 

this code in 'test.php' file.

i trying pass varriable php, using ajax so:

$.ajax({             type: 'post',             url: "test.php",             data: "test" + test,             success: function (data) {             console.log(test);             }         }); 

when try dump output, returns me null (im passing , dumping output in same file, tried passing file , dumping there - same result):

var_dump($_post['test']); 

why isn't value passing?

the format of data option incorrect.

change

data: "test" + test, 

to

data: {test: test}, 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -