Sunday, 15 June 2014

ajax - Syntax error in Javascript function -



ajax - Syntax error in Javascript function -

java script

$('#senurl').click(function () { $.ajax({ type: "post", url: "/admin/coupon1/reject", datatype: "json", data: "id="+@model.id+"&url="+@url }); });

referenceerror: expired not defined [break on error] data: "id="+2925+"&url="+expired

you want (but see below):

$('#senurl').click(function () { $.ajax({ type: "post", url: "/admin/coupon1/reject", datatype: "json", data: "id=@model.id&url=@url" }); });

...because have think browser sees, , if @url gets replaced expired server, error can tell browser sees code is:

data: "id="+2925+"&url="+expired // <=== browser sees current code

even better, allow jquery handle potential uri-encoding needed passing object instead:

$('#senurl').click(function () { $.ajax({ type: "post", url: "/admin/coupon1/reject", datatype: "json", data: {id: @model.id, url: "@url"} }); });

if don't want pass jquery object , allow handle uri-encoding you, you'll want handle yourself:

data: "id=@model.id&url=" + encodeuricomponent("@url")

javascript ajax jquery

No comments:

Post a Comment