jQuery .load - url 中的参数 - 多部分、多值
我的参数是从 html 代码中提取的,然后粘贴到 jQuery .load request
中。
Html 代码:
<a href="#" class="employee">John Doe<span>Lead Web Developer</span></a>
从 html 代码中提取参数,在 .click
内:
//Create href + params from name + params from title
var substr = ( $(this).html() ).split('<span>')[0].split(' '); // Get First & Last Name
var JobTitle = $('span', this).html(); // Get Job Title
console.log( JobTitle );
// console log will be multivalue (e.g "Lead Web Developer")
带参数的 jQuery .load 请求
$('.popUp').load("employee.php?FirstName=" + substr[0]+"&LastName=" + substr[1] + "&JobTitle=" + JobTitle, function(){
// Do Stuff When Done
});
但是,我在 FireBug 中看到的 URL 如下所示:
http://host.loc/employee.php?FirstName=John&LastName=Doe&JobTitle=Lead
As you can see, only first word from
var JobTitle
is being used. Why?如何在 URL 中传递多值参数?
My params are being extracted form html code and than pasted into jQuery .load request
.
Html code:
<a href="#" class="employee">John Doe<span>Lead Web Developer</span></a>
Params extraction from html code, inside .click
:
//Create href + params from name + params from title
var substr = ( $(this).html() ).split('<span>')[0].split(' '); // Get First & Last Name
var JobTitle = $('span', this).html(); // Get Job Title
console.log( JobTitle );
// console log will be multivalue (e.g "Lead Web Developer")
jQuery .load request with params
$('.popUp').load("employee.php?FirstName=" + substr[0]+"&LastName=" + substr[1] + "&JobTitle=" + JobTitle, function(){
// Do Stuff When Done
});
But, the URL I can see in the FireBug looks like that:
http://host.loc/employee.php?FirstName=John&LastName=Doe&JobTitle=Lead
As you can see, only first word from
var JobTitle
is being used. Why?How can I past multivalue param inside the URL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您应该使用 encodeURIComponent() 对值进行编码,以允许查询字符串中存在空格
I think you should encode the value using encodeURIComponent() to allow spaces in the querystring
对参数进行编码。
使用 http://api.jquery.com/jQuery.param/ 来处理它你。
例子 -
Encode the params.
Use http://api.jquery.com/jQuery.param/ which would handle it for you.
Example -