本文介绍了SyntaxError:JSON.parse:JSON数据之后的意外非空白字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 在mvc中查看 < script type = text / javascript > function SubmitInfo(formContainer){ alert( in fun); alert(formContainer.serialize()); $ .ajax({ url: User / Index,类型:' post', data:formContainer.serialize(),成功: function (data){ if (data.IsSuccess){ // 清除输入标签 formContainer.find( 输入[type ='text'])。each( function (i,element){ $( this )。val(' '); }); } alert( giii); alert(data.Message); },错误: function (jqXHR,textStatus,errorThrown){ alert(errorThrown); } }); } < / 脚本 > 控制器部分。我的打印 responsr.write(jsonArray )它给出了上述错误 [HttpPost] public JsonResult索引(用户模型) { if (ModelState.IsValid) { JArray JsonArray = new JArray(); JObject jo = new JObject(); 用户puser = 新用户(); puser.USER_NAME = model.USER_NAME.Trim(); puser.EMAIL_ID = model.EMAIL_ID.Trim(); puser.MOBILE_NO = model.MOBILE_NO.Trim(); 列表<用户> tUser = new 列表< Models.User>(); tUser.Add(puser); // GetPageBaseObject.Add(puser); JsonArray =(JArray)JToken.FromObject(tUser); // 。替换(新的正则表达式(\\ n) ,g),); Response.Write(JsonArray); jo [ 消息] = 数据保存Succeffully; jo [ data] = JsonArray; Response.Write(jo.ToString()); return Json(jo [ data ]); } else { return Json( false ); } } } } 解决方案 View In mvc<script type="text/javascript"> function SubmitInfo(formContainer) { alert("in fun"); alert(formContainer.serialize()); $.ajax({ url: "User/Index", type: 'post', data: formContainer.serialize(), success: function(data) { if (data.IsSuccess) { // Clear the input tags formContainer.find("input[type='text']").each(function (i, element) { $(this).val(''); }); } alert("giii"); alert(data.Message); }, error: function (jqXHR, textStatus, errorThrown) { alert(errorThrown); } });}</script>Controller part. My i print responsr.write(jsonArray) It gives the above error[HttpPost] public JsonResult Index(User model) { if (ModelState.IsValid) { JArray JsonArray = new JArray(); JObject jo = new JObject(); User puser=new User(); puser.USER_NAME = model.USER_NAME.Trim(); puser.EMAIL_ID = model.EMAIL_ID.Trim(); puser.MOBILE_NO = model.MOBILE_NO.Trim(); List<User> tUser = new List<Models.User>(); tUser.Add(puser); //GetPageBaseObject.Add(puser); JsonArray = (JArray)JToken.FromObject(tUser);//.Replace(new Regex("\\n", "g"),""); Response.Write(JsonArray); jo["Message"] = "Data Saved Succeffully"; jo["data"] = JsonArray; Response.Write(jo.ToString()); return Json(jo["data"]); } else { return Json(false); } } }} 解决方案 这篇关于SyntaxError:JSON.parse:JSON数据之后的意外非空白字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-19 02:02