Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 如何用URI的前缀替换特殊字符_Angularjs_Angular_Ionic Framework_Ionic4 - Fatal编程技术网

Angularjs 如何用URI的前缀替换特殊字符

Angularjs 如何用URI的前缀替换特殊字符,angularjs,angular,ionic-framework,ionic4,Angularjs,Angular,Ionic Framework,Ionic4,我是爱奥尼亚公司的新员工,我接受了一个女孩的项目,她最近离开了我的工作。 我收到一个缺陷,当用户键入“N/a”来搜索订单时,它在搜索时破坏了URI。一位共同开发人员建议将“/”替换为“%2F”将修复URI中的此问题 对于长期修复,我希望能够读取用户输入的内容,如果其中包含任何特殊字符,则将其替换为此前缀 以下是我的一些代码: async getOrder() { if ( this.searchValue.length < 1) { console.log('search

我是爱奥尼亚公司的新员工,我接受了一个女孩的项目,她最近离开了我的工作。 我收到一个缺陷,当用户键入“N/a”来搜索订单时,它在搜索时破坏了URI。一位共同开发人员建议将“/”替换为“%2F”将修复URI中的此问题

对于长期修复,我希望能够读取用户输入的内容,如果其中包含任何特殊字符,则将其替换为此前缀

以下是我的一些代码:

   async getOrder() {
   if ( this.searchValue.length < 1) {
  console.log('search is empty');
  this.alertService.emptyInput();
} else {
    /**
     * Setup loading controller
     */
    const loading = await this.loadingController.create({
      message: 'Searching..'
    });
    await loading.present();

          // Get access token from storage
     this.storage.get(ACCESS_TOKEN).then((token) => {
       console.log('token from storage: ', token);

       if (this.searchValue === 'N/A') {
         this.searchValue = 'N%2FA';
       }
       const urlOrderNo = this.apiUrl + 'ordersearch/' + this.searchValue;
async getOrder(){
if(this.searchValue.length<1){
log('搜索为空');
this.alertService.emptyInput();
}否则{
/**
*设置加载控制器
*/
const loading=等待this.loadingController.create({
消息:“正在搜索…”
});
等待加载。当前();
//从存储器中获取访问令牌
this.storage.get(访问令牌)。然后((令牌)=>{
log('来自存储器的令牌:',令牌);
如果(this.searchValue==='N/A'){
this.searchValue='N%2FA';
}
const urlOrderNo=this.apiUrl+'ordersearch/'+this.searchValue;
例如,我添加了='N/A',但每次我都需要检查字符串,因为订单号可能也包含特殊字符


有人能帮我吗?

您可以使用以下任何一种方法:
1.
escape()
此方法不会对以下
@/+

2.
encodeURIComponent()
此方法不会对以下
~!()”进行编码。

我更喜欢第二种方法
encodeURIComponent()

因此,请更换

if (this.searchValue === 'N/A') {
  this.searchValue = 'N%2FA';
}
const urlOrderNo = this.apiUrl + 'ordersearch/' + this.searchValue;


您可以使用以下任一方法:
1.
escape()
此方法不会对以下
@/+

2.
encodeURIComponent()
此方法不会对以下
~!()”进行编码。

我更喜欢第二种方法
encodeURIComponent()

因此,请更换

if (this.searchValue === 'N/A') {
  this.searchValue = 'N%2FA';
}
const urlOrderNo = this.apiUrl + 'ordersearch/' + this.searchValue;

encodeURIComponent(this.password)对我有效!谢谢:)encodeURIComponent(this.password)对我有效!谢谢:)