I have a web app that is basically a huge form that will eventually be transformed into a pdf. When the form is submitted, all the input gets sent to a php file that stores them as variables to be added to the pdf. Some of the data I need on the pdf is calculated in JavaScript, so I am using ajax to send those calculated variables to the same php file that the form sends its data to. The ajax call is not sending the data to the php script. I tried to echo some of the variables, but nothing shows up. Here is my ajax call:
$.ajax({
url: 'FMpdf_values.php',
method: 'POST',
data: {elevChartImg : elevChartImg, azChartImg : azChartImg, power_rating : power_rating, antWeight : antWeight, antennaWithRadomeWeight : antWithRadomeWeight,
epa : epa, radome : radome, deicer : deicer, thetaCol : thetaCol, afAmpCol : afAmpCol, dbCol : dbCol, product : product, channelFM : channelFM,
antLongDescription : antLongDescription, antShortDescription : antShortDescription},
success:function(data){
console.log(data);
}
});
The PHP file is just setting the variables to $_POST['some_data'], then that file is included in the PHP file that creates the pdf. I am relatively new to both PHP and ajax, so I apologize if this is an easy fix. I am wondering if it is even possible to get values from the HTML form and ajax in the same file?
FMpdf_values.php:
<?php
//PHP file for getting the values needed for the PDF
//All html element variables are added here, while calculated values are passed through AJAX
header("Content-Type: application/json", true); //For accepting JSON data
//HTML Element Variables
$projectName = $_POST['projectTitle'];
$customer = $_POST['customer'];
$location = $_POST['location'];
$antModel = $_POST['tlantennaModel'];
$specCode = $_POST['specNumber'];
$createdBy = $_POST['completedBy'];
$notes = $_POST['notes'];
$date = date("F j, Y");
$revDate = $_POST['revisionDate'];
$freq = $_POST['channelNum'];
$wavelength = "11807.22891";
$gainVal = $_POST['tlhorPeakPower'];
$erpVal = $_POST['tlhorERP'];
$beamtilt = $_POST['beamTiltVal'];
$firstNull = $_POST['firstNull'];
$secondNull = $_POST['secondNull'];
$rfInput = $_POST['rfInputs'];
$antennaHeightFt = $_POST['antennaHeightFt'];
$antennaHeightMt = $_POST['antennaHeightMt'];
$CORHeightFt = $_POST['CORHeightFt'];
$CORHeightMt = $_POST['CORHeightMt'];
$ovrHeightFt = $_POST['overallHeightFt'];
$ovrHeightMt = $_POST['overallHeightMt'];
$vertLineType = $_POST['tlTypeVertSelect'];
$vertLineLengthFt = $_POST['tlvertft'];
$vertLineLengthMt = $_POST['vertLengthMeters'];
$vertAttenFt = $_POST['tlvertatten'];
$vertAttenMt = $_POST['tlVertAttenMt'];
$horLineType = $_POST['tlTypeHorSelect'];
$horLineLengthFt = $_POST['tlhorft'];
$horLineLengthMt = $_POST['horLengthMeters'];
$horAttenFt = $_POST['tlhoratten'];
$horAttenMt = $_POST['tlhorattenmt'];
$transLineLosskW = $_POST['tranlinelossKW'];
$transLineLossdB = $_POST['tranlinelossdb'];
$transLineEff = $_POST['tlefficiency'];
$antInputPowerkW = $_POST['antennaInputPowerkw'];
$antInputPowerdB = $_POST['antennaInputPowerdBk'];
$isoTranLosskW = $_POST['isoLosskw'];
$isoTranLossdB = $_POST['isoLossdB'];
$filterLosskW = $_POST['filterLosskw'];
$filterLossdB = $_POST['filterLossdB'];
$systemLosskW = $_POST['systemLosskw'];
$systemLossdB = $_POST['systemLossdB'];
$totalLosskW = $_POST['totallosskw'];
$totalLossdB = $_POST['totallossdB'];
$TPOkW = $_POST['poweroutputkw'];
$TPOdB = $_POST['poweroutputdB'];
$systemEff = $_POST['otherSystemEfficiency'];
//Variables from AJAX
$elevChartImg = $_POST['elevChartImg'];
$azChartImg = $_POST['azChartImg'];
$power_rating = $_POST['power_rating'];
$antWeight = $_POST['antWeight'];
$antWithRadomeWeight = $_POST['antWithRadomeWeight'];
$epa = $_POST['epa'];
$radome = $_POST['radome'];
$deicer = $_POST['deicer'];
$thetaCol = $_POST['thetaCol'];
$afAmpCol = $_POST['afAmpCol'];
$dbCol = $_POST['dbCol'];
$product = $_POST['product'];
$channelFM = $_POST['channelFM'];
$antLongDescription = $_POST['antLongDescription'];
$antShortDescription = $_POST['antShortDescription'];
//ThetaCol, afAmpCol, & dbCol are currently JSON encoded objects
$thetaCol = json_decode($thetaCol);
$afAmpCol = json_decode($afAmpCol);
$dbCol = json_decode($dbCol);
die(print_r($_POST));
die(print_r($_POST));?{var1: var1, var2: var2, ...}can be abbreviated to{var1, var2, ...}.$("form").serialize()to get all the fields of the form.console.log(data);show? How, where are you setting thedatavariables:elevChartImg,azChartImgetc.... How are you calling$.ajax()?