Welcome Guest, Not a member yet? Register   Sign In
JSON return string ajax
#1
Sad 
(This post was last modified: 02-01-2021, 02:19 PM by ferb.)

I send form by post, and response will be a json encode

this return controller


$msg = ["tipo" => 'danger',
"icon" => 'fa fa-times',
"msg" => 'Email no encontrado.'];

return $this->response->setJSON($msg);


but retrivied and string


i using codeigniter 4.1.1
Reply
#2

(This post was last modified: 02-02-2021, 02:13 AM by demyr.)

You need Json stringify. Please look for it on internet

An example :

PHP Code:
$('#send-button').click(function(){
     $.each($('#holder').serializeArray(), function() {
    answer[this.name] = this.value;
    
});
             
var answers JSON.stringify(answernull2);
      $.ajax({
          url "<?php echo base_url('your-controller-and-method');?>",
          method"POST",

etc
Reply




Theme © iAndrew 2016 - Forum software by © MyBB