我正在尝试从HTML页面发布到Service Now URL。我无法做到。我会请求有人帮助我。
<html>
<body>
<button onclick="createRecord()">Create Soap</button>
<script src="jquery-1.6.4.js"></script>
<script language="javascript">
function createRecordCallback (xmlHttpRequest, status) {
var sys_id = $(xmlHttpRequest.responseXML).find('sys_id').text();
var tex = $(xmlHttpRequest.responseXML).text();
if (status == "success") {
var sys_id = $(xmlHttpRequest.responseXML).find('sys_id').text();
alert(sys_id);
} else {
alert('error page'+sys_id+'is the sys id');
}
}
function createRecord() {
var sel = '';
var desc_field = 'comments';
var instance = 'abc.service-now.com';
var table = 'incident';
var soapMessage = '<?xml version="1.0" encoding="UTF-8"?>';
soapMessage += '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:inc="http://www.service-now.com/incident">';
soapMessage += '<soapenv:Header/><soapenv:Body><inc:insert>';
soapMessage += '<short_description>' + 'Incident Created' + '</short_description>';
soapMessage += '</inc:insert></soapenv:Body></soapenv:Envelope>';
$.ajax({
url: "https://abc.service-now.com/incident.do?SOAP",
type: "POST",
dataType: "xml",
username: "admin",
password:"admin",
data: soapMessage,
complete: createRecordCallback,
contentType: "text/xml; charset=\"utf-8\""
});
alert(soapMessage);
}
</script>
</body>
</html>
我发布到SOAP端点https://abc.service-now.com/incident.do?SOAP。我正在尝试使用该WebService的插入方法。
只需注意,一个非常相似的代码正在对同一端点进行chrome扩展。
谢谢!