首页 新闻 会员 周边

jquery 调用webservice时的问题(在线等

0
悬赏园豆:50 [待解决问题]

我在用jquery调用webservice时出现了以下现象:(本人工程为asp.net 应用程序)
    
1.在测试时,jquery调用webservice中的方法时一切正常。

2.在我的程序发布到我的本地ISS 5.1服务器上时,在调用webserverice时,"却出现了jquery 使用webservice HTTP/1.1 405 Method Not Allowed"的错误信息

注:我是在一个html网页上用jquery调用时,发现上述现象的。之后,我又换了.aspx的WebForm的网页调用时依然出现上述的现象!希望高手尽快解答,我在线等!!!!

工程截图

index.html(前台代码):

1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <script src="Script/jquery-1.4.2.min.js" type="text/javascript"></script>
5 <script type="text/javascript">
6
7 $(function () {
8
9 /*
10 1、WebService请求类型都为Post,WebService的Url为“[WebServiceUrl]/[WebMethod]”
11 2、contentType声明为Json
12 3、data要用Json的字符串格式传入
13 4、设置了dataType为json后,result就直接为返回的Json对象。
14
15 */
16
17 //调用无参数方法
18 $("#btnHelloWorld").click(function () {
19 $.ajax({
20 type: "POST",
21 contentType: "application/json",
22 url: "WebService1.asmx/HelloWorld",
23 data: "{}",
24 dataType: 'json',
25 success: function (result) {
26 alert(result.d);
27 }
28 });
29 });
30
31 //传入1个参数
32 $("#btnHello").click(function () {
33 $.ajax({
34 type: "POST",
35 contentType: "application/json",
36 url: "WebService1.asmx/Hello",
37 data: "{name:'KiMoGiGi'}",
38 dataType: 'json',
39 success: function (result) {
40 alert(result.d);
41 }
42 });
43 });
44
45 //返回泛型列表
46 $("#btnArray").click(function () {
47 $.ajax({
48 type: "POST",
49 contentType: "application/json",
50 url: "WebService1.asmx/CreateArray",
51 data: "{i:10}",
52 dataType: 'json',
53 success: function (result) {
54 alert(result.d.join(" | "));
55 }
56 });
57 });
58
59 //返回复杂类型
60 $("#btnPerson").click(function () {
61 $.ajax({
62 type: "POST",
63 contentType: "application/json",
64 url: "WebService1.asmx/GetPerson",
65 data: "{name:'KiMoGiGi',age:26}",
66 dataType: 'json',
67 success: function (result) {
68 var person = result.d;
69 var showText = [];
70 for (var p in person) {
71 showText.push(p + ":" + person[p]);
72 }
73 alert(showText.join("\r\n"));
74 }
75 });
76 });
77 });
78
79 </script>
80 <title></title>
81 </head>
82 <body>
83 <p>
84 <input type="button" id="btnHelloWorld" value="HelloWorld" />
85 </p>
86 <p>
87 <input type="button" id="btnHello" value="Hello" />
88 </p>
89 <p>
90 <input type="button" id="btnArray" value="CreateArray" />
91 </p>
92 <p>
93 <input type="button" id="btnPerson" value="GetPerson" />
94 </p>
95 </body>
96 </html>
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Web;
5 using System.Web.Services;
6
7 namespace jQuery_use_webservice
8 {
9 [WebService(Namespace = "http://tempuri.org/")]
10 [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
11 [System.ComponentModel.ToolboxItem(false)]
12
13 [System.Web.Script.Services.ScriptService]
14 public class WebService1 : System.Web.Services.WebService
15 {
16
17 /// <summary>
18 /// 无任何参数
19 /// </summary>
20 /// <returns></returns>
21 [WebMethod]
22 public string HelloWorld()
23 {
24 return "Hello World";
25 }
26
27 /// <summary>
28 /// 传入参数
29 /// </summary>
30 /// <param name="name"></param>
31 /// <returns></returns>
32 [WebMethod]
33 public string Hello(string name)
34 {
35 return string.Format("Hello {0}", name);
36 }
37
38 /// <summary>
39 /// 返回泛型列表
40 /// </summary>
41 /// <param name="i"></param>
42 /// <returns></returns>
43 [WebMethod]
44 public List<int> CreateArray(int i)
45 {
46 List<int> list = new List<int>();
47
48 while (i >= 0)
49 {
50 list.Add(i--);
51 }
52
53 return list;
54 }
55
56 /// <summary>
57 /// 返回复杂类型
58 /// </summary>
59 /// <param name="name"></param>
60 /// <param name="age"></param>
61 /// <returns></returns>
62 [WebMethod]
63 public Person GetPerson(string name, int age)
64 {
65 return new Person()
66 {
67 Name = name,
68 Age = age
69 };
70 }
71 }
72
73 /// <summary>
74 /// 复杂类型
75 /// </summary>
76 public class Person
77 {
78 public string Name { get; set; }
79
80 public int Age { get; set; }
81 }
82
83 }

来了就看看的主页 来了就看看 | 初学一级 | 园豆:150
提问于:2011-04-28 22:24
< >
分享
所有回答(1)
0
邀月 | 园豆:25475 (高人七级) | 2011-04-29 09:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册