ITsolutionWizard
asked on
javascript to xml
I have the following codes to loop each of the item within the html form
and inside of the javascript. I want to generate xml string like
<xml>
<tranid id="test">
<firstname>John</firstname >
<lastname>Smiths</lastname >
</tranid>
</xml>
1. How can I do that in javascript?
2. When the xml string is passed back to c# code behind, will it create any security issue because of xml tag?
and inside of the javascript. I want to generate xml string like
<xml>
<tranid id="test">
<firstname>John</firstname
<lastname>Smiths</lastname
</tranid>
</xml>
1. How can I do that in javascript?
2. When the xml string is passed back to c# code behind, will it create any security issue because of xml tag?
<div class="12u">
<div class="row">
<div class="6u">
<label id="lblfirstname" for="firstname"></label>
<input type="text" id="firstname" placeholder="first name" required />
</div>
<div class="6u">
<label id="lbllastname" for="lastname"></label>
<input type="text" id="lastname" placeholder="last name" />
</div>
</div>
<label id="lblcompanyname" for="companyname"></label>
<input type="text" id="companyname" placeholder="company name" />
<label id="lbladdress" for="address"></label>
<input type="text" id="address" placeholder="address" />
<div class="row">
<div class="6u">
<label id="lblphoneno" for="phoneno"></label>
<input type="text" id="phoneno" placeholder="phone number" />
</div>
<div class="6u">
<label id="lblemail" for="email"></label>
<input type="text" id="email" placeholder="email" />
</div>
</div>
</div>
<script type="text/javascript">
function submit()
{
var str = '';
var elem = document.getElementById('aspnetForm').elements;
for(var i = 0; i < elem.length; i++)
{
str += elem[i].id + ":" + elem[i].value + "&";
}
$.ajax({
type: "POST",
data: '{namestring:"' + str + '"}',
url: "~/redapp.aspx/PostData",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function(response) {
alert(response.d);
}
});
}
function OnSuccess(response) {
alert("Success " + response.d);
}
function DisplayFormValues()
{
var str = '';
var elem = document.getElementById('aspnetForm').elements;
for(var i = 0; i < elem.length; i++)
{
str += elem[i].id + ":" + elem[i].value + "\n";
}
alert(str);
}
</script>
[System.Web.Services.WebMethod]
public static string PostData(string namestring)
{
return "Success";
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER