Right now, I have something similar to the following in my PHP file :
<form >
First name: <input type="text" name="FirstName" value="Mickey"><br>
Last name: <input type="text" name="LastName" value="Mouse"><br>
</form>
<div id="submitParagraphID">
<img src="myImage.png" alt="Success" /> Thank you for submitting your request.
</div>
<div class="row"style="margin-top: 15px;" >
<div class="col-sm-3" id="downloadSetsButtonDiv">
<button class="btn btn-primary" onclick="submitUsingjQuery()">Submit</button>
</div>
</div>
And something like the following in my Javascript file :
function submitUsingjQuery(){
$("#submitParagraphID").show("fast");
console.log("Is console log printing?");
var formdata = $("form").serializeArray();
alert(JSON.stringify(formdata));
}
And I can see the name value pair of the Javascript object. Here’s working JSFiddle example:
[{"name":"FirstName","value":"Mickey"},{"name":"LastName","value":"Mouse"}]
Since I am using PHP, I am able to get some server variables like the username of the person who has logged into the system. For example, var_dump($_SERVER['MELLON_username']);
displays the username.
I am wondering how can I include the above server variable also into the javascript object so that the output would look like the following:
[{"name":"FirstName","value":"Mickey"},{"name":"LastName","value":"Mouse"},{"name":"MELLON_username":"value":"myusername"]
I want to include the server variable above so that I could call a java webservice using Ajax by sending this javascript obeject in the Ajax call.