title: getting data from controller in error function of jquery ajax -- Asp.net MVC
body: <p>I have a jquery ajax script like following</p>
  
  <pre><code>    $.ajax({
              type: "POST",
              url: "Main/receive", // the method we are calling
              contentType: "application/json; charset=utf-8",
              data: JSON.stringify({ 'p':$("#txtname").val() }),
              dataType: "json",
              success: function (result) {
                  alert('Yay! It worked!');
                  // Or if you are returning something
  
              },
              error: function (result) {
                  alert('Oh no zzzz:('+result.responseText);
              }
          });
  </code></pre>
  
  <p>And I am calling to Controller action method. The data is sending to the controller's action method and I am also receiving data from the controller. But the data that I am receiving is inside the error function of jquery ajax.</p>
  
  <p>I want it to be inside the success function.</p>
  
  <p>Why my success function is not getting called.</p>
  
  <p>Following is my controller's action method,</p>
  
  <pre><code>   [HttpPost]
      public string receive(string p)
      {
          ViewBag.name = p;
          return p;
  
      }
  </code></pre>