When submitting forms, I ran across problems in getting POST data in my server-side PHP script. I narrowed it down to a little bit of JQuery/JavaScript that loads JSON data via AJAX into a DataTable.
The form is as follows:
<form class="form-horizontal" action="./scripts/lookup.php" method="post" role="form" id="lookupForm">
<div class ="form-group">
<label for="inputLookup" class="col-sm-2 control-label">Username</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputLookup" name="lookup_name" placeholder="John.Doe" required/>
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<input id="submitUserLookupBtn" name="submitUserLookup" type="submit" value="Lookup" class="btn btn-primary"/>
</div>
</div>
</form>
And then the script:
$("#lookupForm").submit(function (e) {
e.preventDefault();
$.ajax({
type: 'POST',
url: './scripts/lookup.php',
dataType: 'json',
success: function(s) {
LUUTable.fnClearTable();
for(var i = 0; i < s.length; i++) {
LUUTable.fnAddData([
s[i][0],
s[i][1],
s[i][2],
s[i][3],
s[i][4],
s[i][5],
s[i][6],
s[i][7]
]);
}
},
error: function(e) {
if (e.responseText != '') {
console.log("Error: " + e.responseText);
} else {
console.log("Warning: No data to return.");
}
}
});
});
Whenever that code snippet is run, the PHP does not get POST data, however once I comment the script out, POST data is sent to the server. The problem, however, is that this code snippet is where I handle the JSON data returned by the server.
What could be the reason for this causing data not to POST, and how might I either further troubleshoot or mitigate this issue?
Much appreciated!
$.ajaxcall i.edata: $(this).find('#inputLookup').val(){input_lookup : $(this).find('#inputLookup').val()}. Feel free to submit as an answer, thanks!