javascript - My js code does not work as expected unless i use an alert message -
i have input field :
<input class="quantityinput" data-index="@table.rows.indexof(row)" type="number" value="@row[col.columnname]" min="1"/>
here js code :
$(document).ready(function () { $(function () { $(document).on('change', '.quantityinput', function () { var data = { id: $(this).data('index'), value: $(this).val() }; $.getjson("/order/basketsession/", data, function (result) { }); location.reload(true); alert("hi!"); }); });
in controller:
public jsonresult basketsession(int id, int value) { (httpcontext.session["basket"] datatable).rows[id][2] = value; return json(true); }
if don't use alert
, json
func not wok when change value of input field using keybord mouse click increase or decrease 1 one works either if use alert
or not(in chrome)
in firefox doesn't work @ all
i hope understand problem
as pointed out, ajax call , doesn't resolve immediately. without digging details, can use done
method execute code when getjson
returns data.
$(document).ready(function() { $(document).on('change', '.quantityinput', function () { var data = { id: $(this).data('index'), value: $(this).val() }; $.getjson("/order/basketsession/", data).done(function(){ location.reload(true); console.log("hi!"); }); }); });
this works because getjson
return promise event happen in future. can find more info getjson
, promises here.
Comments
Post a Comment