Calling a web service from javascript and .net 2.0

Thank you all for your help, fishing rod.

Hello everybody,

Is it possible to call a web service (on my localhost) from jquery on a simple HTML page inside an asp.net 2.0 web application using visual studio 2005?

<script type="text/javascript">
    $(document).ready(function(){
        $('#button1').click(function(){                
            $('#targetDiv').load('http://localhost/testservice/Service1.asmx/HelloWorld',null,function(){alert('test')});
        });
    });
</script>

Am I having a 500 error? Not sure if this is possible to do so?

thanks, core

+3
source share
5 answers

By default, ASP.Net does not include web methods for queries GET(this is what it .load()does without data ). Scott Guthrie has a good blog post on how to incorporate GET into web methods .

, - ( ), $.post() :

$('#button1').click(function(){                
  $.post('http://localhost/testservice/Service1.asmx/HelloWorld',
    function(data) { $('#targetDiv').html(data); }
  );
});

.load() POST , :

$('#button1').click(function(){                
  $('#targetDiv')
    .load('http://localhost/testservice/Service1.asmx/HelloWorld', {});
});

{} - , .load() POST GET.

+2

- -, ajax.

+1
0

A 500 error means your web service made an exception. Check the event log to see what the problem is, or debug the web service to find out.

0
source

Source: https://habr.com/ru/post/1746575/


All Articles