Reputation: 19
I am passing my string to PHP through AJAX using $.Ajax
.
I'm trying to pass this string:
action=abc¶meter=C&W
The AJAX splits the C&W
on the basis of &
, so the request comes in this format:
$action = "abc";
$parameter = "C";
How can I pass it as C&W
, without it being split into a different parameter?
Upvotes: 1
Views: 792
Reputation: 20748
Using bog-standard JavaScript (no jQuery), you can use encodeURIComponent
:
var url = "action=" + encodeURIComponent(action) + "¶meter=" + encodeURIComponent(param);
Upvotes: 1
Reputation: 382150
You should let jQuery do the encoding for you :
$.ajax({
url: someUrl, // <- no parameter here
data: {action:'abc', parameter:'C&W'},
...
Upvotes: 7