javascript - Form post warning message after upgrading jquery -
i have upgraded jquery 1.10.2. using jquery migrate , having warning message "jquery.parsejson requires valid json string"
i have not understood how can correct that. can me out best solution of how can remove warning message
the javascript follows:
function search() { $.ajax({ cache: false, contenttype: "application/json; charset=utf-8", datatype: "html", url: "@url.action("search")", data: json.stringify({mymodel: $("#datefrom").val()}), success: function (data) { $("#newdiv").html(data); }, error: function (request, status, error) { displayerror(parseerrorfromresponse(request.responsetext, "unknown error"), true); } }); }
in controller:
public partialviewresult search(mymodel mymodel) { return partialview("searchresult", mymodel); }
parseerrorfromresponse:
function parseerrorfromresponse(responsetext, defaulterror) { var text = responsetext.replace("<title>", "titlestart"); var startindex = text.indexof("titlestart"); var endindex = text.indexof("titleend"); return (startindex == -1 || endindex == -1) ? defaulterror : text.substring(startindex + 10, endindex); }
you need send data json
.
where have data: $("#datefrom").val()
, replace data: json.stringify({$("#datefrom").val()})
.
edit: may need send json.stringify({(mymodel: $("#datefrom").val()})
.
Comments
Post a Comment