如何使用JSON调用webmethod [英] How to call webmethod using JSON

查看:77
本文介绍了如何使用JSON调用webmethod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我已经开始学习JSON.

我在ASP.NET中创建了一个WEB SERVICE(asmx),我在其中使用了JSON.
我想用jQuery,JavaScript或Ajax调用网络方法.

现在,我想使用2个或更多参数调用我的方法.


所以我不知道如何使用这个即时版的Ajax,jQuery.

Hello Friends i have start learning JSON.

I create a WEB SERVICE(asmx) in ASP.NET i used JSON in it.
I want to call webmethods with jQuery, JavaScript or Ajax.

Now i want to call my Method taking 2 or more parameter.


so i don''t know how to use this i m beginner of Ajax,jQuery.

推荐答案

看看这个,非常适合您的要求.

如何使用ASP.NET AJAX从客户端JavaScript调用Web服务 [带有AJAX扩展的客户端Web服务调用 [ ^ ]
Take a look at this, perfect fit for what you are asking for.

How to call a Web Service from client-side JavaScript using ASP.NET AJAX[^]

Also, you can refer to Client-Side Web Service Calls with AJAX Extensions[^]



您可以通过Jquery ajax实现.假设您有一个Web方法Report1,该方法带有2个参数fromDate和toDate.


You can achive this by Jquery ajax. Lets say you have a web method Report1 that takes 2 parameter fromDate and toDate.

[WebMethod]
public static String Report1(String fromDate,String toDate)
{
  //function body
}



现在您可以通过jquery ajax调用上述方法



now you can call the above method by jquery ajax


.ajax({ 输入:"POST", 网址:"default.aspx/Report1", 数据:"{fromDate:" 1/1/2011,toDate:" 6/30/2011}" contentType:"application/json; charset = utf-8", dataType:"json", beforeSend:function(){
.ajax({ type: "POST", url: "default.aspx/Report1", data: "{fromDate:''1/1/2011'',toDate:''6/30/2011''}" contentType: "application/json; charset=utf-8", dataType: "json", beforeSend: function () {


这篇关于如何使用JSON调用webmethod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆