jquery - My Javascript is not working when having two function? -
i have 2 functions called on $(document).ready()
in main.js file:
$(document).ready(function () { updatevalue(); locationvalue(); });
updatevalue()
works fine, when call locationvalue()
, breaks. seems due getwards()
function called in locationvalue()
.
here 2 functions:
function updatevalue() { $(document.body).on("change", ".quantity", function () { var proid = $(this).attr("data"); var quatity = $(this).val(); $.ajax({ type: "get", url: "/cart/updatevalue", data: { proid: proid, quantity: quatity }, success: function (data) { $(".cart_box").html(data); } } ); $.ajaxsetup({ cache: false }); }); } function locationvalue() { $("#city").change(function () { var cityid = $("#city").val(); alert(cityid); getwards(cityid); }); } function getwards(cityid) { alert("in show"); $.ajax({ url: "/checkout/wards", data: {cityid: cityid}, datatype:"json", type:"post", error:function() { alert("an error occured"); }, success:function(data) { var items=""; $.each(data, function(i,item)) { items+="<option value=\"" + item.value + "\">" + item.text + "</option>"; }); $("#ward").html(items); } }); }
alert(cityid)
in locationvalue()
shows correctly if comment out call getwards()
. what's wrong code?
function getwards(cityid) { alert("in show"); $.ajax({ url: "/checkout/wards", data: {cityid: cityid}, datatype:"json", type:"post", error:function() { alert("an error occured"); }, success:function(data) { var items=""; $.each(data, function(i,item))
^^ have 1 many ')'... delete last ) , might work.
{ items+="<option value=\"" + item.value + "\">" + item.text + "</option>"; }); $("#ward").html(items); } });
Comments
Post a Comment