I am trying to pass a string through ajax, however the string is a query string taken from a search and looks something like this:
search=&site=0&salesperson=0&referral=0&product=0&estimate=0&sort=date&open=on&filter_sbmt=Filter+Prospect&limit=30
So when I pass it through ajax as the variable url=search=&site=0...
it sets the $_POST['url']="search=",
and then separates &site as a new post, rather than keeping the entire string in one.
$.ajax({
type : 'POST',
url : '//'+base_url+'/ajax2/customer-search.php',
data : 'url='+url,
success : function(data) {
$('#customers_table').html(data);
}
});
I have tried decoding it with json both on the php side and javascript side. This did not help either. I am out of ideas.
How can I get this string "search=&site=0&salesperson=0&referral=0&product=0&estimate=0&sort=date&open=on&filter_sbmt=Filter+Prospect&limit=30"
on to ajax/customer-search.php
2
Answers
You can use parse_str()
jQuery will encode the data for you if you pass an object and not a string.
Alternatively, modern browsers have a URLSearchParams object that will encode the data for you: