2

当我尝试执行以下脚本时..我得到一个error。我正在尝试使用 JSON 接收数据。

function loadData() {
      isLoading = true;
      $('#loaderCircle').show();
      alert("OOOOO");
      $.ajax({

          url: apiURL,
          dataType: 'json',
          data: { page: page }, // Page parameter to make sure we load new data
          success: function(data) {
              isLoading = false;
              $('#loaderCircle').hide();

              // Increment page index for future calls.
              page++;

              // Create HTML for the images.
              var html = '';
              var i = 0, length = data.length, image;
              alert(data.length);
              for (; i < length; i++) {
                  image = data[i];

                  html += '<li class="polaroid"><div class="optionbg"></div><div class="optionback"><span>Necklaces</span></div><div class="options"><span class="favs">14</span><span class="fav">like it!</span></div><a href="http://www.google.co.in"><img src="' + image.preview + '" width="180" height="' + Math.round(image.height / image.width * 180) + '"></a></li>';

              }

              // Add image HTML to the page.
              $('#tiles').append(html);

              // Apply layout.
              applyLayout();
          },
          error: function(result) {
              $('#qqq').text(JSON.stringify(result));
              //alert(JSON.stringify(result));
          }
      });
    };

网络服务:

 <WebMethod(Description:="Gets the Categories")> _
    <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
    Public Function GetCategories() As String
        Dim details As New List(Of Nodes)()

        Using ds As Data.DataSet = db.ExecuteDataSet(CommandType.Text, "SELECT NodeID,NodeName FROM Nodes WHERE ParentID='1'")
            Dim JaggedArray As String()() = New String(ds.Tables(0).Rows.Count - 1)() {}
            Dim i As Integer = 0
            For Each rs As DataRow In ds.Tables(0).Rows
                Dim node As New Nodes()
                node.NodeId = rs("NodeId").ToString
                node.NodeName = rs("NodeName").ToString
                details.Add(node)
                'JaggedArray(i) = New String() {rs("NodeName").ToString(), rs("NodeID").ToString()}
                i = i + 1
            Next
        End Using
        Dim js As New JavaScriptSerializer()
        Dim strJSON As String = js.Serialize(details.ToArray)
        Return strJSON
    End Function

JSON输出:

<string xmlns="http://localhost:54511/"> [{"NodeId":"BK01","NodeName":"Books","ParentId":null,"Likes":null},{"NodeId":"CO01","NodeName":"Computers","ParentId":null,"Likes":null},{"NodeId":"GA01","NodeName":"Gaming","ParentId":null,"Likes":null},{"NodeId":"MO01","NodeName":"Mobile & Accessories","ParentId":null,"Likes":null}] </string>

错误:

{"readyState":4,"responseText":"<html>\r\n <head>\r\n <title>Request format is unrecognized for URL unexpectedly ending in '/GetCategories'.</title>\r\n <style>\r\n body {font-family:\"Verdana\";font-weight:normal;font-size: .7em;color:black;} \r\n p {font-family:\"Verdana\";font-weight:normal;color:black;margin-top: -5px}\r\n b {font-family:\"Verdana\";font-weight:bold;color:black;margin-top: -5px}\r\n H1 { font-family:\"Verdana\";font-weight:normal;font-size:18pt;color:red }\r\n H2 { font-family:\"Verdana\";font-weight:normal;font-size:14pt;color:maroon }\r\n pre {font-family:\"Lucida Console\";font-size: .9em}\r\n .marker {font-weight: bold; color: black;text-decoration: none;}\r\n .version {color: gray;}\r\n .error {margin-bottom: 10px;}\r\n .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }\r\n </style>\r\n </head>\r\n\r\n <body bgcolor=\"white\">\r\n\r\n <span><H1>Server Error in '/EntLib5' Application.<hr width=100% size=1 color=silver></H1>\r\n\r\n <h2> <i>Request format is unrecognized for URL unexpectedly ending in '/GetCategories'.</i> </h2></span>\r\n\r\n <font face=\"Arial, Helvetica, Geneva, SunSans-Regular, sans-serif \">\r\n\r\n <b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.\r\n\r\n <br><br>\r\n\r\n <b> Exception Details: </b>System.InvalidOperationException: Request format is unrecognized for URL unexpectedly ending in '/GetCategories'.<br><br>\r\n\r\n <b>Source Error:</b> <br><br>\r\n\r\n <table width=100% bgcolor=\"#ffffcc\">\r\n <tr>\r\n <td>\r\n <code>\r\n\r\nAn unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code>\r\n\r\n </td>\r\n </tr>\r\n </table>\r\n\r\n <br>\r\n\r\n <b>Stack Trace:</b> <br><br>\r\n\r\n <table width=100% bgcolor=\"#ffffcc\">\r\n <tr>\r\n <td>\r\n <code><pre>\r\n\r\n[InvalidOperationException: Request format is unrecognized for URL unexpectedly ending in '/GetCategories'.]\r\n System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +405913\r\n System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +212\r\n System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) +47\r\n System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +193\r\n System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +93\r\n System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +155\r\n</pre></code>\r\n\r\n </td>\r\n </tr>\r\n </table>\r\n\r\n <br>\r\n\r\n <hr width=100% size=1 color=silver>\r\n\r\n <b>Version Information:</b>&nbsp;Microsoft .NET Framework Version:2.0.50727.4971; ASP.NET Version:2.0.50727.4971\r\n\r\n </font>\r\n\r\n </body>\r\n</html>\r\n<!-- \r\n[InvalidOperationException]: Request format is unrecognized for URL unexpectedly ending in '/GetCategories'.\r\n at System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)\r\n at System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath)\r\n at System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)\r\n at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)\r\n at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()\r\n at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)\r\n-->","status":500,"statusText":"Internal Server Error"}

4

1 回答 1

1

我在这里你可以找到解决方案: http: //aspadvice.com/blogs/ssmith/archive/2007/09/04/FIX-Request-format-is-unrecognized-for-URL-unexpectedly-ending-in.aspx

于 2013-07-09T22:16:14.420 回答