Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 从javascript和.NET2.0调用web服务_Jquery_Asp.net Ajax - Fatal编程技术网

Jquery 从javascript和.NET2.0调用web服务

Jquery 从javascript和.NET2.0调用web服务,jquery,asp.net-ajax,Jquery,Asp.net Ajax,谢谢大家的帮助,罗德 大家好 是否可以使用VisualStudio2005在asp.NET2.0WebForm应用程序内的普通html页面中从jquery调用web服务(在我的本地主机上) <script type="text/javascript"> $(document).ready(function(){ $('#button1').click(function(){ $('#targetDiv')

谢谢大家的帮助,罗德

大家好

是否可以使用VisualStudio2005在asp.NET2.0WebForm应用程序内的普通html页面中从jquery调用web服务(在我的本地主机上)

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

$(文档).ready(函数(){
$('#按钮1')。单击(函数(){
$('#targetDiv')。加载('http://localhost/testservice/Service1.asmx/HelloWorld,null,函数(){alert('test')});
});
});
我有500个错误?不确定这样做是否可行

谢谢,
rod

你确定这行是正确的吗?
您是否尝试过通过浏览器直接调用Web服务?

改用Jquery+Ajax:


500错误意味着您的web服务引发了异常。查看事件日志以找出问题所在,或者调试web服务以找出问题所在。

在web服务中启用web方法,以便可以使用ajax调用它。

默认情况下,ASP.Net不会为
GET
请求启用web方法(这是无数据的应用程序所做的)

但是,请记住,它们被禁用是有原因的(主要是安全原因),您可能只想使用,如下所示:

$('#button1').click(function(){                
  $.post('http://localhost/testservice/Service1.asmx/HelloWorld',
    function(data) { $('#targetDiv').html(data); }
  );
});
$('#button1').click(function(){                
  $('#targetDiv')
    .load('http://localhost/testservice/Service1.asmx/HelloWorld', {});
});
或者使用虚拟数据对象创建触发器POST,如下所示:

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

{}
是关键,.

如果我在没有'/HelloWorld'的情况下转到此链接,我可以在浏览器中看到该服务…但是我如何调用名为'HelloWorld()的方法呢