1

My code is like Below.

$.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");
        }
    }
});

Above code works when passing data without '@' sign

Example:

//passing Hello
txtemail = "Hello"

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

But if i pass email like below it gives error

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

Any Suggestions How to overcome this matter

Unicron
  • 7,275
  • 1
  • 26
  • 19
Lasantha
  • 391
  • 1
  • 3
  • 13

2 Answers2

3

Use encodeURIComponent() on the E-Mail address.

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

@ is a reserved character in a URL (for the username:password@domain scheme) and needs to be percent encoded.

Unicron
  • 7,275
  • 1
  • 26
  • 19
  • Thank You. i replace @ sign with %40 when sending email. again end point i have to replace again (%40 to @). I did it long way. Thank You for the easy method. – Lasantha Mar 24 '11 at 04:24
0

You will have to encode the url as Unicron said u can also use the escape() function for this....

url:'http://www.sample.com/checkmail/'+escape($('#txtemail').val())
Scrappy Cocco
  • 1,192
  • 3
  • 21
  • 38
  • 3
    Don't use `escape()`. See: http://stackoverflow.com/questions/75980/best-practice-escape-or-encodeuri-encodeuricomponent – Tomalak Mar 22 '11 at 07:30