【发布时间】:2012-12-12 12:06:37
【问题描述】:
我希望用户能够将 URL 地址的一部分更改为他们的邮政编码。我有一个文本框和按钮,希望将值提交给 URL。
jQuery:
jQuery(document).ready(function($) {
$.ajax({
url : "http://SomeAddress.com/" + PostCode + ".json",
dataType : "jsonp",
success : function(parsed_json) {
HTML:
<input type="text" id="GetPostCode" />
<button id="SetPostCode">Set This Post Code</button>
jQuery:
$("#SetPostCode").click(function() {
var PostCode = document.getElementById("GetPostCode").value;
$("#GetPostCode").val(" ");
return false;
});
我明白这条线
$.ajax({
url : "http://api.wunderground.com/api/2508132ae0c7601a/geolookup/conditions/q/UK/" + PostCode + ".json",
那样不行,但我不知道还能做什么。有人可以告诉我我需要做什么才能使其正常工作吗?
【问题讨论】:
-
唯一不起作用的原因是 PostCode 不是全球性的......如果它是你的排序
-
为什么不在点击处理程序中
var PostCode行之后的$.ajax呢? -
+1 @CarlSaldanha 您在 click 函数中设置了
PostCode变量,因此您无法从其他地方访问它。 -
那很简单...谢谢大家
标签: javascript jquery ajax url input