jquery - Send JSON data to PHP and use it -


i have issue sending json data ajax php file , use upload server.

if i'm making echo of variable $email_info->name returned data value empty. i've tried json_decode doesn't it.

this code have,

jquery:

$( document ).on('click', '#send_touch', function(){      new_email = [];      new_email.push({     name: $('#name').val(),     phone: $('#phone').val(),     email: $('#email').val(),     interested_in: $('#interested_in').val(),     user_id: $('#email_user_id').val()     });      new_email = json.stringify({email: new_email}, null, "\t");          $.ajax({             url: "core.php",             type: "post",             data: { newmail: new_email                   },             success: function(data){                   alert(data)                       },             error: function(){             }         });      }); 

php:

if ($_post['newmail']) {   $timestamp = time();   $new_email = json_decode($_post['newmail'], true);   $email_info = $new_email->email[0];   // new email  mysql_query("insert " . $dbprefix . "touches (date, user_id, name, phone, email, interested_in, seen, status) values ('".safesql($timestamp)."', '".safesql($email_info->user_id)."', '".safesql($email_info->name)."','".safesql($email_info->phone)."', '".safesql($email_info->email)."', '".safesql($email_info->interested_in)."', '0', '1')") or die("query failed: " . mysql_error());   echo $email_info->name;  } 

if make echo on php side $_post['newmail'] returned this:

{ \"email\": [     {         \"name\": \"john doe\",         \"phone\": \"1234567\",         \"email\": \"john@doe.com\",         \"interested_in\": \"text here..\",         \"user_id\": \"1\"     } ] } 

how can fix this?

replace part in php :

$new_email = json_decode($_post['newmail'], true); 

by :

if (get_magic_quotes_gpc()) {     $_post['newmail'] = stripslashes($_post['newmail']); } $new_email = json_decode($_post['newmail'], true); 

this should fix issue.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -