【发布时间】:2014-08-20 08:09:50
【问题描述】:
在具有类别列表的网页上,每个类别标题都以这种格式链接:http://localhost/admin/category/unpublish/2
我写了下面的js代码,试图捕获url和segments'unpublish'(action)和'2'(id),需要把请求发送到http://localhost/admin/category
$('#statusChanges a').click(function(evt) { // use the click event of hyperlinks
evt.preventDefault();
var url = $(location).attr('href');
// var action = url.segment(3); /*JS console complains that url.segment() method undefined! */
// var id = url.segment(4);
$.ajax({
type: "GET",
url: $(location).attr('href'),
dat: '',
/* do I need to fill the data with json data: {"action": "unpublish, "id": 2 } ? but I don't know how to get the segments */
success: function(data) {
$('.statusSuccess').text('success!');
},
error: function(data) {
$('.statusSuccess').text('error!');
}
});
}); // end of status change
【问题讨论】:
-
这个问题可能有用。 stackoverflow.com/questions/406192/…
标签: javascript jquery ajax url