0

質問:

ソート可能なjQuery用の以下のJavaScriptハンドラーがあります。
問題は、エラー(parseerror)が発生することです。
問題はデータ型です:JSON + contentType:'application / json'は、データが適切に送信されるために必要なようです。

ただし、応答をJSON形式にする必要はありません。アプリケーション/jsonリクエストに対するテキスト/プレーンレスポンスが必要です。

それは不可能ですか?
または:どうすればそれを適切に行うことができますか(JSON応答を与える必要はありません)?

Http-Handler:

Imports System.Web
Imports System.Web.Services

Public Class FMS_SaveTeaserSort
    Implements System.Web.IHttpHandler

    Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

        Dim strpagesget As String = context.Request.QueryString("pages")
        Dim strPagesPost As String = context.Request.Form("pages")

        Dim json As String = Nothing
        Using sr As New System.IO.StreamReader(context.Request.InputStream)
            json = sr.ReadToEnd()
        End Using ' sr

        json = context.Server.UrlDecode(json)
        'Dim customer As Byte() = New Byte(System.Convert.ToInt32(context.Request.InputStream.Length) - 1) {}
        'context.Request.InputStream.Read(customer, 0, customer.Length)
        'Dim customerJSON As String = System.Text.Encoding.UTF8.GetString(customer)
        ' TODO: deserialize the JSON back to a Customer object


        context.Response.ContentType = "text/plain"
        context.Response.Write("Hello World!")

    End Sub


    ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property


End Class

JavaScriptコード:

$(function () {
    //$('#sortable').sortable();


    $('#sortable').sortable({
        update: function (event, ui) {
            var strMovedElementId = ui.item.attr('id');
            //alert("post");
            $.ajax({
                url: './ajax/FMS_SaveTeaserSort.ashx'
                        , type: 'POST'
                        , cache: false
                        //, contentType: 'application/json'
                        //, contentType: 'text/plain'
                        //, contentType: "application/x-www-form-urlencoded" 
                        , contentType: "application/json; charset=utf-8"
                        , dataType: "json"
                        //, data: JSON.stringify({ pages: $(this).sortable('toArray') })
                        , data: { pages: $(this).sortable('toArray') }
                        , success: function (result) {
                            //alert("success");
                        }


                        , error: function (request, type, errorThrown) {
                            var message = "There was an error with the AJAX request.\n";
                            //alert(type);

                            switch (type) {
                                case 'timeout':
                                    message += "The request timed out.";
                                    break;
                                case 'notmodified':
                                    message += "The request was not modified but was not retrieved from the cache.";
                                    break;
                                case 'parsererror':
                                    message += "Parser error: Bad XML/JSON format.";
                                    break;
                                default:
                                    message += "HTTP Error (" + request.status + " " + request.statusText + ").";
                            }
                            message += "\n";
                            alert(message);


                            switch (request.status) {
                                case 400:
                                    alert('HTTP ' + request.status + ': ' + request.statusText + '\nThe request cannot be fulfilled due to bad syntax');
                                    break;
                                case 401:
                                    alert('HTTP ' + request.status + ': ' + request.statusText + '\nAuthentication is possible but has failed or not yet been provided');
                                    break;
                                case 403:
                                    alert('HTTP ' + request.status + ': ' + request.statusText + '\nAccess denied');
                                    break;
                                case 404:
                                    alert('HTTP ' + request.status + ': ' + request.statusText + '\nThe requested page could not be found but may be available again in the future');
                                    break;
                                case 405:
                                    alert('HTTP ' + request.status + ': ' + request.statusText + '\nA request was made of a page using a request method not supported by that page');
                                    break;
                                case 408:
                                    alert('HTTP ' + request.status + ': ' + request.statusText + '\nThe server timed out waiting for the request');
                                    break;
                                case 410:
                                    alert('HTTP ' + request.status + ': ' + request.statusText + '\nThe requested page is no longer available');
                                    break;
                                case 500:
                                    alert('HTTP ' + request.status + ': ' + request.statusText + '\nA generic error message, given when no more specific message is suitable\nError description:\n' + request.responseText);
                                    break;
                                case 502:
                                    alert('HTTP ' + request.status + ': ' + request.statusText + '\nThe server was acting as a gateway or proxy and received an invalid response from the upstream server (fastcgi-crash?)');
                                    break;
                                case 503:
                                    alert('HTTP ' + request.status + ': ' + request.statusText + '\nThe server is currently unavailable (overloaded or down)');
                                    break;
                                case 504:
                                    alert('HTTP ' + request.status + ': ' + request.statusText + '\nThe server was acting as a gateway or proxy and did not receive a timely response from the upstream server');
                                    break;
                                case 511:
                                    alert('HTTP ' + request.status + ': ' + request.statusText + '\nThe client needs to authenticate to gain network access');
                                    break;
                                case 0:
                                    alert('HTTP ' + request.status + ': ' + request.statusText + '\nRequest aborted');
                                    break;
                                default:
                                    alert('HTTP ' + request.status + ': ' + request.statusText + '\nUnknown error: \nError description:\n' + request.responseText);
                            } // End Switch

                        }


                        , complete: function (result) {
                            //alert("complete");
                        }

            }); // End ajax
        } // End Update
    }); // End Sortable


    $('#sortable').disableSelection()
});
4

1 に答える 1

3

dataTypeからjsonに変更text

于 2012-08-07T07:28:49.270 に答える