0

I'm working on webmatrix with json helper and also jquery.form.js. After posting the data to the server, my response data look like this:

"\u003cli\u003monster2010 is not a valid email.\u003c/li\u003e""\u003cli\u003eaclassgclass@yahoo.com is already in use by you.\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);

i have also tried to encode the writer using

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

I've also tried:

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);

        }

can some help?

Ifeanyi Chukwu
  • 3,187
  • 3
  • 28
  • 32

1 Answers1

2

JSON is a format for encoding structured data not for encoding HTML. The value of your dataType parameter should be 'html' given what you are sending from the server.

Mike Brind
  • 28,238
  • 6
  • 56
  • 88