簡體   English   中英

如何使用JS將使用表單數據的JSON對象傳遞給Rest服務

[英]How to pass a JSON object using form data to a rest service using JS

我有一個可以接受字符串的rest網絡服務。 我想將json對象作為字符串傳遞給此服務。 我必須使用帶有某些文本字段的HTML頁面,並且必須將表單數據傳遞給服務。 可以幫忙嗎?

謝謝

你可以試試這個

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM