首页 新闻 搜索 专区 学院

jquery中$.ajax和$.get 有啥区别啊?

0
[已关闭问题] 关闭于 2012-04-04 19:18

问题是这样,我用$.get在服务端取数据的时候,能取到啊, 但是用$.ajax就娶不到值了,返回的是null。 并且是同一个id,$.get就可以,$.ajax就不行。

        public string GetDeptInfoByID(string guid)
{
var list = context.LS_Department.SingleOrDefault(i => i.id == guid);
return ParseToJSON(list);
}

用$.ajax的时候list为null,

sql语句是这样:

exec sp_executesql N'SELECT TOP (1) 
[Extent1].[id] AS [id],
[Extent1].[Department_name] AS [Department_name],
[Extent1].[Department_manager] AS [Department_manager],
[Extent1].[Department_phone] AS [Department_phone],
[Extent1].[Department_describe] AS [Department_describe]
FROM [dbo].[LS_Department] AS [Extent1]
WHERE [Extent1].[id] = @p__linq__0
',N'@p__linq__0 nvarchar(4000)',
@p__linq__0=N'''14A103FF-F0D5-4426-AA84-DA733899E5C3'''

在查询分析器里面查不出数据。而改成这样就可以:

SELECT TOP (1) 
[Extent1].[id] AS [id],
[Extent1].[Department_name] AS [Department_name],
[Extent1].[Department_manager] AS [Department_manager],
[Extent1].[Department_phone] AS [Department_phone],
[Extent1].[Department_describe] AS [Department_describe]
FROM [dbo].[LS_Department] AS [Extent1]
WHERE [Extent1].[id] = '14A103FF-F0D5-4426-AA84-DA733899E5C3'

这是为什么啊?



 

涅槃子的主页 涅槃子 | 菜鸟二级 | 园豆:208
提问于:2012-03-04 13:43
< >
分享
所有回答(4)
0

我用$.get在服务端取数据的时候,能取到啊, 但是用$.ajax就娶不到值了,返回的是null

下面贴的却是SQL的代码,你到底是问jquery还是sql

水牛刀刀 | 园豆:6350 (大侠五级) | 2012-03-04 14:48
0

建议列出$.ajax调用参数

dudu | 园豆:37797 (高人七级) | 2012-03-04 16:19

我是这样写的:

//        $.ajax({
        //            type: "POST",
        //            contextType: "application/json",
        //            url: "../WebService/Demo_forAnything.asmx/GetDeptInfoByID",
        //            data: { guid: "'"+$(this).attr("value")+"'" },
        //            success: function (responseText) {
        //                //                $(responseText.d).each(function () {
        //                //                    alert($(this).toString());
        //                //                });
        //                alert(responseText);
        //            },
        //            dataType: 'json',
        //            async: false,
        //            error: function (result, stats, ex) {
        //                alert(result.status);
        //                alert(stats);
        //                alert(ex);
        //            }
        //        });

支持(0) 反对(0) 涅槃子 | 园豆:208 (菜鸟二级) | 2012-03-04 17:48
0

把你的js请求部分贴出来看看

paseo | 园豆:262 (菜鸟二级) | 2012-03-05 09:20
0

$.get 不能post数据,$.ajax 的功能就更强大了,至于你使用$.ajax没结果是因为你使用有问题,还有你服务器端是怎样接收数据的,这个得和客户端相应配合。

慧☆星 | 园豆:5545 (大侠五级) | 2012-03-05 14:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册