0

我正在使用 json helper 和 jquery.form.js 开发 webmatrix。将数据发布到服务器后,我的响应数据如下所示:

"\u003cli\u003monster2010 不是有效的电子邮件。\u003c/li\u003e""\u003cli\u003eaclassgclass@yahoo.com 已被您使用。\u003c/li\u003e"

StringWriter writer = new StringWriter();
Json.Write("<li>" + user_mobile[i] + " is already in use by you.</li>", writer);
Json.Write("<li>" + user_mobile[i] + " is not a valid phone number.</li>", writer);
Response.Write(writer);

我也尝试使用编码作家

var json = json.Encode(writer); //razor

我也试过:

Json.Write(Json.Encode("<li>" + user_mobile[i] + " is already in use by you.</li>"), writer);
Json.Write(Json.Encode("<li>" + user_mobile[i] + " is not a valid phone number.</li>"), writer);

var options = {
            //            target: '#',   // target element(s) to be updated with server response 
            beforeSubmit: showRequest,  // pre-submit callback 
            success: showResponse,  // post-submit callback 

            // other available options: 
            //url:       url         // override for form's 'action' attribute 
            //type:      type        // 'get' or 'post', override for form's 'method' attribute 
            dataType: 'json'        // 'xml', 'script', or 'json' (expected server response 
        };

        // bind to the form's submit event 
        $('#frm_basicinfo').submit(function () {
            $(this).ajaxSubmit(options);

            return false;
        });
        function showRequest(formData, jqForm, options) { 
            var queryString = $.param(formData);

            alert('About to submit: \n\n' + queryString);

            return true;
        }

        // post-submit callback 
        function showResponse(responseText, statusText, xhr, $form) {

            alert('status: ' + statusText + '\n\nresponseText: \n' + responseText);

        }

可以帮忙吗?

4

1 回答 1

2

JSON 是一种用于编码结构化数据的格式,而不是用于编码 HTML。您的dataType参数值应该是'html'您从服务器发送的内容。

于 2012-06-03T16:30:20.067 回答