How to add a variable to URL of $.ajax({ url : " "});
jQuery(document).ready(function($) { var PostCode=1; $.ajax({ url : "http://SomeAddress.com/"+PostCode +".json", dataType : "jsonp" //.... more stuff }); $("#SetPostCode").click(function() { PostCode = document.getElementById("GetPostCode").value; $("#GetPostCode").val(" "); return false; });});
Above would work as PostCode is now global to the jQuery and can be accessed anywhere