c# - What is wrong with this JQuery AJAX code -
i facing problem ajax code. using mvc3 our project. requirement bind dropdown value using ajax when page load. happens when loading page, ajax request send controller , return ajax function , binds exact values in dropdown. (when page refreshed or first time load) not binding retrieved value. rather showing default value. pls see code , suggest me doing wrong.
edit: tried use async property false. not @ send controller action method getting data.
code
$.ajax({ type: "post", contenttype: "application/json; charset=utf-8", url: '@url.action("getuser", "invoices")', data: "{'id':" + json.stringify(currval) + "}", datatype: "json", async: true, success: function (data) { $("#user-" + curr).select2("data", { id: data.value, name: data.text }); $(this).val(data.value); } });
thanks,
let's action method below
public jsonresult hello(int id) { return json(new { success = true }, jsonrequestbehavior.allowget); }
and jquery should below
<script language="javascript" type="text/javascript"> $(document).ready(function () { var currval = 2; $.ajax({ url: 'url', async: true, type: 'post', contenttype: 'application/json; charset=utf-8', data: json.stringify({ id: currval }), success: function (data) { } }); }); </script>
Comments
Post a Comment