【问题标题】:How to pass a JSON object using form data to a rest service using JS如何使用表单数据将 JSON 对象传递给使用 JS 的休息服务
【发布时间】:2012-02-14 18:46:59
【问题描述】:

我有一个可以接受字符串的休息网络服务。我想将一个 json 对象作为字符串传递给该服务。我必须使用带有一些文本字段的 HTML 页面,并且必须将表单数据传递给服务。有人可以帮忙吗??

谢谢

【问题讨论】:

标签: javascript html json rest


【解决方案1】:

你可以试试这个

 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);  
    }

【讨论】:

猜你喜欢
  • 2014-01-14
  • 2017-01-02
  • 1970-01-01
  • 2012-03-16
  • 2015-07-27
  • 1970-01-01
  • 2015-10-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多