晨鸟科技

标题: IIS7.5 AjaxMethod 未定义解决办法 [打印本页]

作者: xueshuai    时间: 2010-9-13 17:54
标题: IIS7.5 AjaxMethod 未定义解决办法
首先,交代下背景:% y8 K( s  k6 g
最近调试作业智能批改系统,其中在作业批改页用到了一点 ajax 技术(教师修改主观类题目分数需局部刷新),今天测试发现程序上传到windows server 2008 r2 的服务器上出现“AjaxMethod 未定义”错误,如下图:, G/ _5 i$ c- D- Z, t3 ^/ x
[attach]127[/attach]
6 [+ g- q; b- m
" o4 U5 F; v7 u* w网上未找出此问题解决方法,纠结半天,最后修改服务器配置,问题解决...
, j* H" ]# s) N
/ Z; ~6 l8 i5 q7 Q" w8 A下面总结解决方法:
, j; H2 r$ s2 a, @. A' h3 N6 s  G先看页面js代码
  1. <script language="javascript">7 f  |5 G+ S6 Q& Z" C% n7 o
  2.     var questionID;0 s$ x/ K9 o+ s* R  k2 g9 s7 M
  3.     function $(ID)4 d, R, R! ^3 r, y* E/ Y
  4.         {
      P* j8 K& ~% o, T4 w3 H
  5.             if(document.all)- _: l+ y6 t1 Y0 N
  6.                 return document.all[ID];
    6 |1 ~3 _$ I: N- A
  7.             else if(document.getElementById)! q4 r" {* V! u+ ]* g% S
  8.                 return document.getElementById(ID);9 O5 D: C. Y+ o3 u: Y, A) d# \. V
  9.             else: ~; |* v; l1 L" U( K2 y
  10.                 return null;
    # }0 ~! }# B8 g
  11.         }: c# o! U0 S8 J( s( d2 ~- f& A

  12. % Y0 _; R+ k4 s# g' n5 z
  13.     function callback_test1(res)! U) X9 D( ^$ b. u* N6 q
  14.     {
    5 U7 E  U1 V1 M) C
  15.         if(res.value =="-1")
    : U: ~3 S2 b7 S  I6 \
  16.         {' {2 O0 G7 `: K  L! H& P( t
  17.             alert("必须输入数字");( _4 p' x/ H: I; @
  18.         }
    6 P- a7 R/ p+ k# g% `
  19.         else if(res.value == "-2")
    1 D" g6 L. j# a. s8 t: w! m
  20.         {
    6 k3 Y. ]1 o2 d1 S- C2 F9 x- j: _4 w  a
  21.             alert("得分不能超过题目标准得分");
      |, L5 }/ L9 d
  22.         }
    $ b% O0 t) ^1 b6 W2 d0 Z
  23.         else{
    - s7 w0 o7 `) T0 l+ l- {, g
  24.             var array  = res.value.split(",");% N3 `8 s* r9 y4 ~* X
  25.             document.getElementById("mark"+questionID).innerHTML = array[0];8 k, _1 P& d  d( l& l/ p1 P9 v3 C
  26.             document.getElementById('totalMark').innerHTML = array[1];+ C& I( P! n  d0 J0 [
  27.             alert("修改成功!");. z; d4 K  N$ ^+ Z4 D! ^
  28.         }
    ( W6 s/ f- x  X& A: Q
  29.            
    ' L2 k& ^+ g% J: |
  30.     }
    2 G4 v8 p4 `# Q+ z7 G# f: B% }* j1 m
  31.     function totalMark(spiID)
    * z0 q0 ?% I. Z% |% a
  32.     {
    8 u7 b7 Q! l) `0 \, G
  33.         AjaxMethod.TotalMark(spiID,callback_totalMark);
    # b$ d9 Y: X4 ~. H% e
  34.     }8 |0 b, g7 N& t$ c$ g0 L
  35.     function editMark(btnID)
    6 a9 t$ r: g1 l
  36.     {
    5 M8 t4 e( c: |$ k) F
  37.         var txtID = "txt"+btnID.substring(3,btnID.length);
    . e& u" P6 l! N; ]& `- S- l8 \7 j3 s

  38. 2 ~6 r6 U- F$ K5 S
  39.         var studentPaperID = document.all.hiddenSpi.value;
    # ~6 L/ c# V$ g( k
  40.         questionID = btnID.substring(3,btnID.length);
    , V. v# P8 z7 h8 p
  41.            
    , T5 P+ z3 _, Z7 D2 j8 ^; |2 a
  42.         var mark = parseInt($(txtID).value);  L; u/ q* @# m- L
  43.        AjaxMethod.EditDiscussMark(studentPaperID,questionID,mark,callback_test1);        ; c& h3 ]: v# d8 c" q& Q
  44.     }0 n4 Q  e. k0 f5 r+ P
  45. </script>
复制代码
1.页面.cs文件中的Page_Load须包含
  1.                         Ajax.Utility.RegisterTypeForAjax(typeof(Ajax.AjaxMethod));
    " }0 p/ [' c  f* Y8 R6 G4 o) l
复制代码
2.AjaxMethod类中添加
  1.         [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]+ a$ `( ]% l' N, v% r  R
复制代码
3.Global.asax的Application_Start方法添加
  1. Ajax.Utility.HandlerPath = "csharpwrapper";
复制代码
4.web.config中的<httpHandlers>和<handlers>分别添加
  1.                         <add verb="POST,GET" path="csharpwrapper/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>" T+ z2 x" L* v

  2. . g# p2 H. `. n/ O" q  v
  3.       <add name="AjaxMethod" type="Ajax.PageHandlerFactory, Ajax" verb="POST,GET" path="ajax/*.ashx" />  //IIS版本为7.0以上添加
    . a+ B2 F) R# c" l- w* S2 F3 V
复制代码
5.打开IIS,点击“应用程序池”——右键“高级设置”——启用32位应用程序“True”
* _4 h0 w( ^9 h8 a$ x& h, |[attach]128[/attach]
8 x$ C8 x3 G" F: ~, W# [8 ?+ s- W% G+ B& v% O& z7 \+ Q' R9 u3 @
问题解决




欢迎光临 晨鸟科技 (http://www.chenniao.com/cprofessor/) Powered by Discuz! X3.2