Note that there are some explanatory texts on larger screens.

plurals
  1. POjson parsing error syntax error unexpected end of input
    primarykey
    data
    text
    <p>I got the following piece of code</p> <pre><code>function pushJsonData(productName) { $.ajax({ url: "/knockout/SaveProduct", type: "POST", contentType: "application/json", dataType: "json", data: " { \"Name\" : \"AA\" } ", async: false, success: function () { loadJsonData(); }, error: function (jqXHR, textStatus, errorThrown) { alert(textStatus + " in pushJsonData: " + errorThrown + " " + jqXHR); } }); } </code></pre> <p>Notice that I hard coded the data value. The data get pushed into the database fine. However, I keep getting the error "parsing error syntax error unexpected end of input". I am sure my data is in correct JSON syntax. When I checked with on Network of Chrome inspector the saveProduct request showed the data is correct. </p> <pre><code>{ "Name": "AA" } </code></pre> <p>This POST request did not have response. So I am clueless as to where the parse error was coming from. I tried using FireFox browser. the same thing happened.</p> <p>Can anyone give some idea as to what is wrong?</p> <p>Thanks, </p> <p>P.S. Here is the controller code</p> <pre><code>namespace MvcApplJSON.Controllers { public class KnockoutController : Controller { // // GET: /Knockout/ public ActionResult Index() { return View(); } [HttpGet] public JsonResult GetProductList() { var model = new List&lt;Product&gt;(); try { using (var db = new KOEntities()) { var product = from p in db.Products orderby p.Name select p; model = product.ToList(); } } catch (Exception ex) { throw ex; } return Json(model, JsonRequestBehavior.AllowGet); } [HttpPost] public void SaveProduct (Product product) { using (var db = new KOEntities()) { db.Products.Add(new Product { Name = product.Name, DateCreated = DateTime.Now }); db.SaveChanges(); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload