Why isn't my code submitting this data?
Hi Experts,
This is a highly condensed version of my code to make it easier to hopefully get some help.
I have a code that returns just one department code based on user Id.
This works.
It works because the value of the code returned is stored in this input textbox control:
- <input name="deptId" id="deptId" type="text" width="300" value="<?=$deptId;?>" class="changeable" />
Then I pass the value of deptId to Ajax code below:
- <script type="text/javascript">
function CallService() {
- //Creating an object to hold token form field
myToken = new Object();
myToken.Token = $("#token").val();
//Creating an object to hold form fields
myData = new Object();
- // Creating variables to hold data from textboxes. First building associated details
myData.org = $("#deptId").val();
$.ajax({
type: "POST",
url: "proxySave.php",
data: {
data: JSON.stringify(myData),
token: myToken.Token
},
dataType: "json",
async: false,
success: function (response) {
alert("Record has been added successfully.");
window.location.reload();
}
});
return false;
}
</script>
When I click the submit button below, I should get an alert "Record has been added successfully"
When I get that message, I look into the database, I see the value. I don't get the message and the value is not getting saved to the database.
-
<button type="submit" id="btnSubmit" onclick="CallService();" style="background-color:#E5E4E2 !important;width:105px; border:outset;padding:7px;border-color:#fff;"><span style="color:#000;font-weight:normal;">Submit<br/> Request</span></button><br /><br />
Am I missing a bit in the Ajax code?
Your help, as usual is greatly appreciated