调用asp.net的WebMethod与jQuery的错误PARAMS [英] Calling asp.net webmethod with params from jquery errors

查看:160
本文介绍了调用asp.net的WebMethod与jQuery的错误PARAMS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置管理一个简单的WebMethod这是我从jQuery和果然叫其返回......然后我说的方法参数和添加的PARAMS jQuery的,但与

它的错误

 消息:无效的JSON原始:一,堆栈跟踪:
 

我的签名在我的webmethod是像这样

  [WebMethod的]
    公共静态字符串GETDATE(字符串之一,字符串二)
    {
        返回是;
    }
 

和我的jQuery是这样的,我究竟做错了什么?

  $。阿贾克斯({
                键入:POST,
                网址:MyService.aspx / GETDATE
                数据:{之一:值,之二:值},
                的contentType:应用/ JSON的;字符集= UTF-8,
                数据类型:JSON,
                成功:函数(MSG){
                    警报(msg.d);
                },
                错误:函数(MSG){
                警报('错误');
                }

            });
 

解决方案

尽量附上您的数据参数报价:

 数据:{之一:值,之二:值}
 

I managed to setup a simple webmethod which i called from jquery and sure enough it returns ... then i added parameters on the method and added the params to jquery but it errors with

        Message":"Invalid JSON primitive: one.","StackTrace":"

my signature on my webmethod is like so

    [WebMethod]
    public static string GetDate(string one, string two)
    {
        return "yes";
    }

and my jquery is like this, what am i doing wrong?

                $.ajax({
                type: "POST",
                url: "MyService.aspx/GetDate",
                data: { one: "value", two: "value" },
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                    alert(msg.d);
                },
                error: function(msg) {
                alert('error');
                }

            });

解决方案

Try enclosing your data parameter in quotes:

data: '{ one: "value", two: "value" }',

这篇关于调用asp.net的WebMethod与jQuery的错误PARAMS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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