Arish
Arish

Reputation: 342

encoding and decoding url issue with ajax

How can I encode multiple URLs in jquery before sending it via ajax to php page and also how to decode it in php page.

Here is the html:

<form method="post">
<textarea id="multiple_url"></textarea>
<button id="check_url">Check</button>
</form>

<div id="Check_result"></div>

Here is jquery:

$('#check_url').click(function(){

var multiple_url = $('#multiple_url').val();

$.ajax({  
type: "POST",  
url: "urls.php",  
data: multiple_url=' +multiple_url,
success: function(results) {  
$('div#Check_result').html(results);
}
});

}

Here is urls.php:

$multiple_url = $_POST['multiple_url'];

echo $multiple_url;

Now in textarea when I post like this:

http://yahoo.com
http://facebook.com
http://google.com

I get the following out put:

http://yahoo.com http://facebook.com http://google.com

But when i post like this:

http://yahoo.com
https://www.facebook.com/photo.php?fbid=540632575958397&set=a.215213765166948.56326.100000349796150&type=1&theater
http://google.com

I got the broken output as seen below:

http://yahoo.com https://www.facebook.com/photo.php?fbid=540632575958397

What happening here is that it is ignoring everything that come after "&" in the url.

How can I resolve this issue?

Upvotes: 0

Views: 578

Answers (1)

Quentin
Quentin

Reputation: 944430

Pass data an object, not a string.

data: { multiple_url: $('#multiple_url').val() }

jQuery will then handle escaping the data for you.

Upvotes: 1

Related Questions