如何将 Ajax 请求发送到同一服务器的不同 url
How to send Ajax request to different url of same server
我正在向我的服务器发送一个 ajax 请求,如下所示:
var data = '';
$.ajax({
type: 'GET',
url: 'api/getnews/home/post/'+title,
data: data,
datatype: 'json',
success: function (data) {
var obj = JSON.parse(data)[0].fields;
console.log(obj);
}
});
url变成
http://127.0.0.1:8000/home/post/api/getnews/home/post/title
, if I am at
http://127.0.0.1:8000/home/post
但是,我希望它是:
任何建议..
你可以试试url
window.location.origin + '/api/getnews/home/post/' + title
或者
'/api/getnews/home/post/' + title
喜欢kusiaga
我正在向我的服务器发送一个 ajax 请求,如下所示:
var data = '';
$.ajax({
type: 'GET',
url: 'api/getnews/home/post/'+title,
data: data,
datatype: 'json',
success: function (data) {
var obj = JSON.parse(data)[0].fields;
console.log(obj);
}
});
url变成
http://127.0.0.1:8000/home/post/api/getnews/home/post/title , if I am at http://127.0.0.1:8000/home/post
但是,我希望它是:
任何建议..
你可以试试url
window.location.origin + '/api/getnews/home/post/' + title
或者
'/api/getnews/home/post/' + title
喜欢kusiaga