问题是这样,我用$.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'
这是为什么啊?
我用$.get在服务端取数据的时候,能取到啊, 但是用$.ajax就娶不到值了,返回的是null
下面贴的却是SQL的代码,你到底是问jquery还是sql
建议列出$.ajax调用参数
我是这样写的:
// $.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);
// }
// });
把你的js请求部分贴出来看看
$.get 不能post数据,$.ajax 的功能就更强大了,至于你使用$.ajax没结果是因为你使用有问题,还有你服务器端是怎样接收数据的,这个得和客户端相应配合。