user1194310
user1194310

Reputation: 129

How to post data to a server as an xml using html or jsp

I want to post the data of a form as an xml to the server using html or jsp. I have tried posting the data in html but I am able to get the xml but not post the xml. I have given the code i have written below. I am using Rest endpoint.

<html>
<head> 
<script type="text/javascript">
function generateXML(formName) {

var str="";

for(i=0; i<document.myForm.elements.length; i++)
{
   var fieldName = document.myForm.elements[i].name;
   var fieldValue = document.myForm.elements[i].value;
   str += "<" + fieldName + ">" ;
    str += fieldValue ;
   str += "</" + fieldName + ">" ;
}
document.getElementById('xml').value = str;
}
</script>
</head>
<body>
<h3>Conduit HTML Enrollment RESTful Web Service Handle Test</h3>
<form name="myForm" method="get" action="http://pc161742:8080/rest/services/htmlTestApp/htmltestProcess:1.0">
Token:<input type="text" name="token"><br />
FirstName:<input type="text" name="Fname"><br /> 
<input type="hidden" name="xml" id="xml" value=""/>
<input type="submit" onClick="generateXML(this)"/>
</form>
</body>
</html>

I am getting error like"com.adobe.idp.dsc.DSCRuntimeException: Internal error." Please let me know what I am doing wrong.

Thanks

Upvotes: 0

Views: 1864

Answers (1)

imxylz
imxylz

Reputation: 7937

try JQuery.ajax:

var ajaxurl="http://pc161742:8080/rest/services/htmlTestApp/htmltestProcess:1.0";
var str="";

for(i=0; i<document.myForm.elements.length; i++)
{
   var fieldName = document.myForm.elements[i].name;
   var fieldValue = document.myForm.elements[i].value;
   str += "<" + fieldName + ">" ;
    str += fieldValue ;
   str += "</" + fieldName + ">" ;
}

$.ajax({
    url: ajaxurl,
    data: str, 
    type: 'POST',
    contentType: "text/xml",
    dataType: "xml",
    success : parse_result,
    error : show_error
}); 

function parse_result(xml){
    //
}
function show_error(){
    //
}

See also jQuery ajax post to web service.

Upvotes: 2

Related Questions