[Solved] jQuery Ajax Error: The length of string exceeds the value set on the maxjson length property

ashish007
 
on Nov 05, 2021 11:52 AM
1126 Views

image save in databse and display jquery c#

FileUpload11 and btnupload inside datalist.

code not work error show

error during serialization or deserialization using the JSON java scriptserialzier. The length of string exceeds the value set on the maxjson length property

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
       $(function () {
           var reader = new FileReader();
           var fileName;
           var contentType;
           $('input[type=file]').change(function () {
               if (typeof (FileReader) != "undefined") {
                   var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.jpg|.jpeg|.gif|.png|.bmp)$/;
                   $($(this)[0].files).each(function () {
                       var file = $(this);
                       if (regex.test(file[0].name.toLowerCase())) {
                           fileName = file[0].name;
                           contentType = file[0].type;
                           reader.readAsDataURL(file[0]);
                       } else {
                           alert(file[0].name + " is not a valid image file.");
                           return false;
                       }
                   });
               } else {
                   alert("This browser does not support HTML5 FileReader.");
               }
           });
 
           $('#btnUpload').on("click", function () {
               var byteData = reader.result;
               byteData = byteData.split(';')[1].replace("base64,", "");
               $.ajax({
                   type: "POST",
                   url: "Default12.aspx/InsertImage",
                   data: '{byteData: "' + byteData + '", imageName: "' + fileName + '", contentType: "' + contentType + '" }',
                   contentType: "application/json; charset=utf-8",
                   dataType: "json",
                   success: function (response) { alert(response.d); },
                   error: function (response) { alert(response.responseText); }
               });
               return false;
           });
       });
</script>

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
ashish007
 
on Nov 11, 2021 08:11 AM

But code work correctly button taken oustside datalist. when button taken inside datalist no error show in console mode and image not save in databse.

dharmendr
 
on Nov 11, 2021 08:22 PM
ashish007 says:
$('#btnUpload').on("click", function () {

Change with below code.

$('[id*=btnUpload]').on("click", function () {