jQuery.Ajax Format Path
jQuery.Ajax Format Path
我有一个简单的问题,我似乎找不到答案。我想用动态变量格式化jQuery.ajax()中的URL路径,例如:
/submit/{ZIPCODE}
有没有一种简单的方法可以格式化它?({邮政编码}将由表单上的文本框提供。
使用普通的 javascript 字符串连接,例如
$.ajax({
url: "/submit/" + "12345",
});
其中"12345"是您的 texbox 中的值
更多详情请见此处:如何将文本框值传递给 jQuery .ajax 方法?
假设邮政编码可用作 ID 为 zipcode
的 HTML input
元素,您可以这样做:
$.ajax({
url: "/submit/" + $('#zipcode').val(),
});
或者这个:
$.ajax("/submit/" + $('#zipcode').val())
.done(function(){
// code to run when successful
})
.fail(function(){
// code to run on failure
})
;
也许你正在寻找jQuery.param http://api.jquery.com/jQuery.param/。
此方法将对象的格式设置为查询字符串。例如
var dict = {
zipCode : 78457,
property2 : "hi there"
};
$.param(dict) // returns "zipCode=78457&property2=hi+there"
相关文章:
- 正在使用$location.path(.)路由ng视图
- gulp Iconify任务抛出错误TypeError:Path必须是字符串.收到false
- paper.js animation along a path
- 使用.format在一些HTML代码中插入文本,会出现错误(Python)
- Format for Excel VBA addWatermarkFromText
- "responsed_to|format|“;引发UnknownFormat错误
- Animating text along an circular path with svg & javascr
- 如何将参数应用于String.prototype.format函数
- Raphael Path十字路口不工作
- res.sendFile(path.join(__dirname, '../public', '
- path没有方法'parse'在Meteor JS中
- 如何使用Y.Number.format和decimalPlaces
- Angular JS$location.path(..)未启动路由控制器
- $location.path获取上一个路径
- D3未捕获类型错误:path.data不是函数
- Angularjs$location.path()无法定位到当前路由器
- TypeError:format.match不是矩angularJS中的函数
- 获取笔刷内Path的d个值
- Joomla: image src path?
- jQuery.Ajax Format Path