Krishna Raj
Krishna Raj

Reputation: 866

send URL from one page to another using ajax request

I need to send URL from one page which contains a form, to another page to check whether the link exist in my database or not. so there are URLs with special characters such as '+' '%' and some part of the URL is html encoded, and some are not. so I cannot encode and send the URL to decode from the receiver page.

$('#searchbutton').click(function(){
    var url = $('#urltext').val();
    $('#datatodiv').load("searchlink.php?url="+url);
});

When I input the URL "http://www.example.com/ae2/STUDIO+CHANNEL+PRO/" which received at the searchurl.php page as "http://www.example.com/ae2/STUDIO CHANNEL PRO/" where the '+' is changed to empty space. There are cases in which encoded data such as "%20" etc used.

Upvotes: 1

Views: 554

Answers (2)

Rory McCrossan
Rory McCrossan

Reputation: 337560

You can use encodeURI() to encode a url:

var url = encodeURI($('#urltext').val());

Example fiddle

This will at least ensure that the URL values being sent have a consistent encoding.

Upvotes: 1

Suresh Kamrushi
Suresh Kamrushi

Reputation: 16086

Try to use PHP functions -

base64_encode()
base64_decode()

Upvotes: 1

Related Questions