I am trying to send JSON encoded
string to PHP file through ajax
.
I tried this but the $_POST
is empty in the ajax target file.
var html = $.ajax({
type: "POST",
url: "getControl.php",
data:js_post_array,
dataType: 'json',
async: false,
success: function (data, status)
{
//alert('here');
//$("#notiDesc").text(data.msg);
}
}).responseText;
js_post_array
contains json encoded string
{ 'business_name': 'test', 'business_type': 'R', 'type': '', 'total_sku_in_store': '',
'speciality': '', 'first_name': '', 'last_name': '', 'title': '',
'responsible_for_wine_buying': '', 'responsible_for_events': '', 'address1': '' }
but in the getControl.php
file I tried print_r($_POST)
that shows an empty array.
But when I just copy this string and paste here data:js_post_array,
instead of js_post_array
then it works fine.
What I am doing wrong?