Javascript API调用中的标点编码
我正在用JavaScript请求一个房地产API。我发送了一个街道地址,它会将有关房产的信息发送给我。它适用于大多数地址。但是,对于地址中有句点的地址(the street=U.s.395)来说,它不起作用,我想知道这个标点符号是否会使它失效,如果是的话,它是如何正确编码的Javascript API调用中的标点编码,javascript,jquery,api,Javascript,Jquery,Api,我正在用JavaScript请求一个房地产API。我发送了一个街道地址,它会将有关房产的信息发送给我。它适用于大多数地址。但是,对于地址中有句点的地址(the street=U.s.395)来说,它不起作用,我想知道这个标点符号是否会使它失效,如果是的话,它是如何正确编码的 // grab address from html function getAddress() { address = $('.js-pma-address').val(); address = $.trim
// grab address from html
function getAddress() {
address = $('.js-pma-address').val();
address = $.trim(address);
...
data(address, locale);
}
// compile data for API query
function data(address, locale) {
dataObj.Key = ...;
dataObj.Address = address;
dataObj.LastLine = locale.toString();
...
compileRequest(dataObj);
}
// create url for API request
function compileRequest(dataObj) {
var request = 'http://rc.api.sitexdata.com/sitexapi/sitexapi.asmx/AddressSearch?';
request += $.param(dataObj);
runQueries(request);
}
// run api query
function runQueries(request) {
$.ajax({
url: 'lp/proxy.php',
data: {requrl: request + '&reportType=187'},
dataType: 'xml'
})
尝试使用
encodeURIComponent()
。。。如果标点符号是罪魁祸首,那就应该纠正它
// compile data for API query
function data(address, locale) {
dataObj.Key = ...;
dataObj.Address = encodeURIComponent(address); // <-- Right here
dataObj.LastLine = locale.toString();
...
compileRequest(dataObj);
}
//为API查询编译数据
函数数据(地址、区域设置){
dataObj.Key=。。。;
dataObj.Address=encodeURIComponent(Address);//尝试使用encodeURIComponent()
…如果标点符号是罪魁祸首,那么应该纠正它
// compile data for API query
function data(address, locale) {
dataObj.Key = ...;
dataObj.Address = encodeURIComponent(address); // <-- Right here
dataObj.LastLine = locale.toString();
...
compileRequest(dataObj);
}
//为API查询编译数据
函数数据(地址、区域设置){
dataObj.Key=。。。;
dataObj.Address=encodeURIComponent(Address);//尝试使用encodeURIComponent()
…如果标点符号是罪魁祸首,那么应该纠正它
// compile data for API query
function data(address, locale) {
dataObj.Key = ...;
dataObj.Address = encodeURIComponent(address); // <-- Right here
dataObj.LastLine = locale.toString();
...
compileRequest(dataObj);
}
//为API查询编译数据
函数数据(地址、区域设置){
dataObj.Key=。。。;
dataObj.Address=encodeURIComponent(Address);//尝试使用encodeURIComponent()
…如果标点符号是罪魁祸首,那么应该纠正它
// compile data for API query
function data(address, locale) {
dataObj.Key = ...;
dataObj.Address = encodeURIComponent(address); // <-- Right here
dataObj.LastLine = locale.toString();
...
compileRequest(dataObj);
}
//为API查询编译数据
函数数据(地址、区域设置){
dataObj.Key=。。。;
dataObj.Address=encodeURIComponent(地址)//