所以我正在尝试向服务器发送 Ajax 请求,但我需要从请求中删除初始问号
代码:
$(document).ready(function(){
(function($){
function processForm( e ){
var callid = $('.callid').val();
var pin = $('.pin').val();
var urlFinal = callid+'/'+pin;
$.ajax({
url: 'https://httpbin.org/get/',
dataType: 'text',
type: 'get',
contentType: 'application/x-www-form-urlencoded',
//$(this).serialize()
data: urlFinal,
success: function( data, textStatus, jQxhr ){
console.log('success' + data.streamFileUrl)
$('.overlay').show();
$('#video').html( data.streamFileUrl );
},
error: function( jqXhr, textStatus, errorThrown ){
console.log('OH NOES');
$('.incorrect').show()
}
});
e.preventDefault();
}
$('#form').submit( processForm );
})(jQuery);
})
结果:
https://httpbin.org/get/?1234/1234
我追求的是:
https://httpbin.org/get/1234/1234
最佳答案
当您发送 GET 请求时,jQuery 会自动为您将数据添加到查询字符串中。
为避免这种情况,请将 urlFinal
附加到您提供给 url
的字符串,而不是将其添加到 data
参数。
var urlFinal = callid + '/' + pin;
$.ajax({
url: 'https://httpbin.org/get/' + urlFinal,
dataType: 'text',
type: 'get',
contentType: 'application/x-www-form-urlencoded',
success: function(data, textStatus, jQxhr) {
// ...
},
// ...
});
关于javascript - 从 jQuery 中的 ajax 请求中删除初始问号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50253779/