2012-04-18 12 views
0

ウェブプログラミングに新しいです。私はここでajaxを使って問題を抱えています。私はjson beigを読んでいます。 要件はInternet Explorerのブラウザを使用することです、私は本当にここに選択肢がありませんが、それを使用する必要があります。 私の問題は、関数が成功して実行されていないことです。私は、エラーが何も表示されていないので、なぜここからどうやって行くべきなのかについては、あまり確かではありません。このコードはちょうど残して辞職した私の同僚によって与えられています。以下はjQuery.ajaxは成功しません:function()

は私のHTMLコードです:

以下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
    <head> 
     <title>ACES Wallboard</title> 
     <link href="StyleSheet.css" rel="Stylesheet" type="text/css" /> 
     <script type="text/javascript" src="Scripts/jquery-1.7.2.min.js"></script> 
     <script type="text/javascript"> 
      <!-- 
      //var obj = jQuery.parseJSON('{"key": [{ "name": "ciq" },{ "name": "lwt" }],"value": [{ "ciq": "3", "lwt": "12" }]}'); 
      //window.onload = function() { 
      //while (true) { 
      //ajax request 
      //for (var i = 0; i < obj.key.length; i++) { 
      // jQuery("#" + obj.key[i].name).html(obj.value[0][obj.key[i].name]); 
      //} 
      //sleep 
      //} 
      //} 
      window.onload = function() { 

       function errorAlert(e, jxr) 
       { 
        alert("Your request is not successful. " + jxr); 
       } 

       jQuery.ajax(
        { 
         type: "POST", 
         async: true, 
         url: 'WallboardHandler.ashx', 
         contentType: "application/json; charset=utf-8", 
         dataType: "json", 
         success: function (obj) { 
          for (var i = 0; i < obj.key.length; i++) { 
           jQuery("#" + obj.key[i].name).html(obj.value[0][obj.key[i].name]); 
          } 
         } 
         error: errorAlert 
        }); 
      }; 
      //--> 
     </script> 
    </head> 
    <body> 
     <div> 
      <div class="panelstyle"> 
       <div class="ciqrowstyle">Call in Queue: <span id="ciq">&nbsp;</span> Calls</div> 
       <div class="lwtrowstyle">Longest Waiting Time: <span id="lwt">&nbsp;</span></div> 
       <div> 
        <table style="border:5px solid black;font-family:Tahoma;font-size:50px;color:black" width="100%"> 
         <tr style="background-color:SteelBlue;font-weight:bold;color:White;"> 
          <td class="gridheader">&nbsp;</td> 
          <td class="gridheader">Avail</td> 
          <td class="gridheader">Unavail</td> 
          <td class="gridheader">Eng</td> 
          <td class="gridheader">Other</td> 
         </tr> 
         <tr> 
          <td class="rowstyle">HQ</td> 
          <td id="11" class="rowstyle">&nbsp;</td> 
          <td id="12" class="rowstyle">&nbsp;</td> 
          <td id="13" class="rowstyle">&nbsp;</td> 
          <td id="14" class="rowstyle">&nbsp;</td> 
         </tr> 
         <tr> 
          <td class="alternatingrowstyle">CDA</td> 
          <td id="21" class="alternatingrowstyle">&nbsp;</td> 
          <td id="22" class="alternatingrowstyle">&nbsp;</td> 
          <td id="23" class="alternatingrowstyle">&nbsp;</td> 
          <td id="24" class="alternatingrowstyle">&nbsp;</td> 
         </tr> 
         <tr> 
          <td class="rowstyle">Div 1</td> 
          <td id="31" class="rowstyle">&nbsp;</td> 
          <td id="32" class="rowstyle">&nbsp;</td> 
          <td id="33" class="rowstyle">&nbsp;</td> 
          <td id="34" class="rowstyle">&nbsp;</td> 
         </tr> 
         <tr> 
          <td class="alternatingrowstyle">Div 2</td> 
          <td id="41" class="alternatingrowstyle">&nbsp;</td> 
          <td id="42" class="alternatingrowstyle">&nbsp;</td> 
          <td id="43" class="alternatingrowstyle">&nbsp;</td> 
          <td id="44" class="alternatingrowstyle">&nbsp;</td> 
         </tr> 
         <tr> 
          <td class="rowstyle">Div 3</td> 
          <td id="51" class="rowstyle">&nbsp;</td> 
          <td id="52" class="rowstyle">&nbsp;</td> 
          <td id="53" class="rowstyle">&nbsp;</td> 
          <td id="54" class="rowstyle">&nbsp;</td> 
         </tr> 
         <tr> 
          <td class="alternatingrowstyle">Div 4</td> 
          <td id="61" class="alternatingrowstyle">&nbsp;</td> 
          <td id="62" class="alternatingrowstyle">&nbsp;</td> 
          <td id="63" class="alternatingrowstyle">&nbsp;</td> 
          <td id="64" class="alternatingrowstyle">&nbsp;</td> 
         </tr> 
        </table> 
       </div> 
       <div class="dtrowstyle">Date: <span id="timestamp">&nbsp;</span></div> 
      </div> 
     </div> 
    </body> 
</html> 

は私WallboardHander.csのコードですが、URLでASHXと呼ばれている理由がわからないのですか?

/* 
* Copyright (C) 2009 CanaPlus Consulting Pte Ltd 
*/ 

using System; 
using System.Collections.Generic; 
using System.Data; 
using System.Data.SqlClient; 
using System.Web; 
using Com.Canaplus.Commons.Config; 
using Com.Canaplus.Commons.Logging; 
using Newtonsoft.Json; 

namespace Com.Canaplus 
{ 
    public class WallboardHandler : IHttpHandler 
    { 
     private static ILogger _logger; 

     protected string GetConnectionString() 
     { 
      return ConfigurationManager.GetInstance().GetConfiguration().GetConnectionString("SS1CMSDBC1"); 
     } 

     protected static ILogger GetLogger() 
     { 
      return _logger ?? (_logger = LoggerFactory.GetLogger(typeof (WallboardHandler).FullName)); 
     } 

     public bool IsReusable 
     { 
      // Return false in case your Managed Handler cannot be reused for another request. 
      // Usually this would be false in case you have some state information preserved per request. 
      get { return false; } 
     } 

     public void ProcessRequest(HttpContext context) 
     { 
      var data = new Dictionary<string, ICollection<JsonType>>(); 
      var keys = new LinkedList<JsonType>(); 
      data.Add("key", keys); 
      var values = new LinkedList<JsonType>(); 
      data.Add("value", values); 
      var value = new ValueType(); 
      values.AddLast(value); 
      try 
      { 
       using (var conn = new SqlConnection(GetConnectionString())) 
       { 
        conn.Open(); 
        var spGetTotalCallInQueue = new SqlCommand("sp_getToTalCallInQueue", conn) 
                {CommandType = CommandType.StoredProcedure}; 
        var o = new KeyType {name = "ciq"}; 
        keys.AddLast(o); 
        value.ciq = spGetTotalCallInQueue.ExecuteScalar().ToString(); 

        var spGetWallBoardMatrixTb = new SqlCommand("sp_getWallBoardMatrixTB", conn) 
                {CommandType = CommandType.StoredProcedure}; 

        var spGetMaxLongestWaitingTime = new SqlCommand("sp_getMaxLongestWaitingTime", conn) 
                 {CommandType = CommandType.StoredProcedure}; 
        o = new KeyType { name = "lwt" }; 
        keys.AddLast(o); 
        value.lwt = spGetMaxLongestWaitingTime.ExecuteScalar().ToString(); 

        var spGetCurrentDateTime = new SqlCommand("sp_getCurrentDateTime", conn) 
                {CommandType = CommandType.StoredProcedure}; 
        o = new KeyType { name = "timestamp" }; 
        keys.AddLast(o); 
        value.timestamp = spGetCurrentDateTime.ExecuteScalar().ToString(); 
       } 
      } 
      catch(Exception e) 
      { 
       GetLogger().Error(e); 
      } 
      context.Response.ContentType = "text/json"; 
      context.Response.Write(JsonConvert.SerializeObject(data, Formatting.Indented)); 
     } 
    } 
} 

あなたは私に人を助けることができる場合、私は本当にあなたのAJAX呼び出しの構文エラーを持っている...

+2

をしようとするだろうか? – mplungjan

+0

質問をする前に構文エラー*を解決してください(本当に見つからない、または理解できない場合を除きます)。あなたがコンソールを見ていたり、JSHintのようなツールを使っていたなら、あなたはそれを見たでしょう。 –

答えて

2

を感謝しています。あなたの成功関数の後にカンマが必要です。これを次のように置き換えてください。

  jQuery.ajax(
       { 
        type: "POST", 
        async: true, 
        url: 'WallboardHandler.ashx', 
        contentType: "application/json; charset=utf-8", 
        dataType: "json", 
        success: function (obj) { 
         for (var i = 0; i < obj.key.length; i++) { 
          jQuery("#" + obj.key[i].name).html(obj.value[0][obj.key[i].name]); 
         } 
        }, 
        error: errorAlert 
       }); 
+0

Drat - 私が読めるものに再フォーマットしているうちに、あなたはそれを私に打ち明けました – mplungjan

0

エラーハンドラの前にカンマがありません。

私は、ロケーションバーに独自にhttp://yourserver.com/WallboardHandler.ashx作業を行い、この

<script type="text/javascript" src="Scripts/jquery-1.7.2.min.js"></script>   
<script type="text/javascript"> 
$(document).ready(function() { 
    $.ajax({ 
    type: "POST", 
    async: true, 
    url: 'WallboardHandler.ashx', 
    contentType: "application/json; charset=utf-8", 
    dataType: "json", 
    success: function (obj) { 
     for (var i = 0; i < obj.key.length; i++) { 
     $("#" + obj.key[i].name).html(obj.value[0][obj.key[i].name]); 
     } 
    }, 
    error: function(e, jxr) { 
     alert("Your request is not successful. " + jxr); 
    } 
    }); 
}); 
関連する問題