【发布时间】:2012-02-14 18:46:59
【问题描述】:
我有一个可以接受字符串的休息网络服务。我想将一个 json 对象作为字符串传递给该服务。我必须使用带有一些文本字段的 HTML 页面,并且必须将表单数据传递给服务。有人可以帮忙吗??
谢谢
【问题讨论】:
标签: javascript html json rest
我有一个可以接受字符串的休息网络服务。我想将一个 json 对象作为字符串传递给该服务。我必须使用带有一些文本字段的 HTML 页面,并且必须将表单数据传递给服务。有人可以帮忙吗??
谢谢
【问题讨论】:
标签: javascript html json rest
你可以试试这个
function callWebService{
var field= document.getElementById('field').value;
//use jquery to convert to json object
//see comment for more info on this
var ws = 'http://localhost:8080/WebServicePath/';
var url = ws + field;
var xmlhttp = null;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
alert("Success");
}
else {
alert("Failure");
}
};
xmlhttp.open('GET', url, true);
xmlhttp.send(null);
}
【讨论】: