gpt4 book ai didi

jquery - 通过Ajax发送包含数据的 "@"符号

转载 作者:行者123 更新时间:2023-12-01 08:24:01 25 4
gpt4 key购买 nike

我的代码如下。

$.ajax({               
url:'http:://www.sample.com/checkmail/'+$('#txtemail').val(),
success: function(data)
{
$('#response').html(data);
if(data!="Success")
{
$('#txtemail').css("background-color","#FF8A8D");
}
else
{
$('#txtemail').css("background-color","white");
}
}
});

上面的代码在传递没有“@”符号的数据时有效

示例:

//passing Hello
txtemail = "Hello"

//ajax response message in firefox
GET http://www.example.com/checkmail/Hello 200 OK 503ms

但是如果我像下面这样传递电子邮件,则会出现错误

Example: 
//passing hello
txtemail = "hello@eee.com"

//ajax response message in firefox
GET http://www.example.com/checkmail/hello@eee.com 400 Bad Request 26ms

任何建议如何解决这个问题

最佳答案

使用encodeURIComponent()在电子邮件地址上。

url:'http://www.sample.com/checkmail/'+encodeURIComponent($('#txtemail').val()),

@ 是 URL 中的保留字符(对于 username:password@domain 方案),需要进行百分比编码。

关于jquery - 通过Ajax发送包含数据的 "@"符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5387871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com