最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Consuming web service in HTML - Stack Overflow

programmeradmin0浏览0评论

I have created a web service and saved its .wsdl file. I want to consume this service in my HTML file by providing its URL.

Can anybody tell me how to call the URL in HTML and use it? Like its done here. /

The only difference is my web service does not have an extention like "asmx?wsdl". Does that makes any difference. I followed that tutorial too but it does not produce any output.

Thank You////

I have created a web service and saved its .wsdl file. I want to consume this service in my HTML file by providing its URL.

Can anybody tell me how to call the URL in HTML and use it? Like its done here. http://www.codeproject.com/Articles/14610/Calling-Web-Services-from-HTML-Pages-using-JavaScr/

The only difference is my web service does not have an extention like "asmx?wsdl". Does that makes any difference. I followed that tutorial too but it does not produce any output.

Thank You////

Share Improve this question edited Apr 2, 2013 at 12:00 NewBee asked Apr 2, 2013 at 9:50 NewBeeNewBee 8397 gold badges18 silver badges43 bronze badges 1
  • You can do this with plain javascript, without jquery: w3schools.com/xml/ajax_intro.asp – Erel Segal-Halevi Commented Oct 14, 2017 at 16:48
Add a comment  | 

3 Answers 3

Reset to default 9

You definitly should get familiar with AJAX. You could use the ajax functionalities provided by jQuery. That's the easiest way, I assume. Take a look at http://api.jquery.com/jQuery.ajax/

You can use this like

$.ajax({
  url: "urltoyourservice.xml"
  dataType: "xml",
}).done(function(data) {
  console.log(data);
});

HTML itself cannot consume a webservice. Javascript ist definitely needed. The existence of your WSDL File looks like you are probably using a XML format as the return of the web service. You have to deal with XML in javascript. Therefore take a look at Tim Downs explanation.

But keep in mind, that your web service URL must be available under the same domain as your consumption HTML-File. Otherwise you'll receive a cross-site-scripting error.

yes you can use ajax but keep in mind you wont be able to make a request across domains. Consuming web services should be done in server side.

To further gain more knowledge about this, read How do I call a web service from javascript

function submit_form(){
        var username=$("#username").val();
        var password=$("#password").val(); 
                var data = { loginName: username, password:password };
                $.ajax( {
                    type: "POST",
                    url:"Paste ur service address here",
                    data: JSON.stringify(data),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async: false,
                    success: function(data){
                        var value = data.d;
                        if(value.UserID != 0){
                            alert.html('success');
                        }
                    },
                    error: function (e) {
                    }
                });  
        }

Try this it will help

发布评论

评论列表(0)

  1. 暂无评论