title: json Webservice that will pass Base64 code that will convert to image
body: <p>Specification:</p>
  <ul>
  <li>Server 2012</li>
  <li>Framework 3.5</li>
  </ul>
  <p>I have already deployed my webservice in the server <code>http://ipaddress/eSignatureWS.asmx?op=SaveImg.</code></p>
  <p><strong>Problem</strong>: when i change the ajax dataType to &quot;json&quot; or &quot;text&quot; it has an Internal Server Error, but when i used &quot;script&quot; it won't have an error but it don't save the image. When i try it locally it works using &quot;json&quot;/&quot;text&quot; but when i deployed it won't work anymore.</p>
  <p>So here's my code:</p>
  <p><strong>Jquery</strong></p>
  <pre><code>function signatureSave() {
  
  var canvas = document.getElementById(&quot;newSignature&quot;); // save canvas image as data url (png format by default)
  var data = canvas.toDataURL(&quot;image/png&quot;);
  var signatureData = data.replace(/^data:image\/(png|jpg);base64,/, &quot;&quot;);
  
  
  var donum = &quot;sampleImg&quot;; //imagename
  $.support.cors = true;
  //var imgData = JSON.stringify(signatureData);
  
  $.ajax({
      type: &quot;Post&quot;,
      async: false,
      url: &quot;http://ipaddress/eSignatureWS.asmx?op=SaveImg&quot;,
      data: { &quot;filename&quot;: donum, &quot;imgBit&quot;: signatureData }, 
      dataType: &quot;json&quot;,
      success: function (data) { //alert(data);
          if (data.match(&quot;true&quot;)) {
              document.getElementById('errorImage').innerHTML = &quot;Successfully Submitted!&quot;;
          }
          else {
              document.getElementById('errorImage').innerHTML = &quot;Error occured.&quot;;
          }
      },
      error: function (XMLHttpRequest, testStatus, errorThrown) {
          document.getElementById('errorImage').innerHTML = errorThrown;
          alert(XMLHttpRequest + testStatus + errorThrown);
      }
  })
  </code></pre>
  <p><strong>Webservice</strong></p>
  <pre><code>[WebMethod]
      [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
      public string SaveImg(string filename, string imgBit)
      {
          try
          {
  
              string filepath = WebConfigurationManager.AppSettings[&quot;ImgLocation&quot;].ToString();
              string imgPath = filepath + filename + &quot;.png&quot;;
  
              //creates a png image signature
              using (FileStream fs = new FileStream(imgPath, FileMode.Create))
              {
                  using (BinaryWriter bw = new BinaryWriter(fs))
                  {
                      byte[] data = Convert.FromBase64String(imgBit);
                      bw.Write(data);
                      bw.Close();
                      JavaScriptSerializer js = new JavaScriptSerializer();
                      string strJSON = js.Serialize(&quot;true&quot;);
                      return strJSON;
                  }
              }
  
          }
          catch (Exception ex)
          {
            
          }
      }
  </code></pre>