0

This is my OpenCart code I don't know what the problem in this code is, but it cant return the value from php ajax page. I tried many ways it wont work so please help me for this problem .

Here is my ajax in OpenCart:

<script type="text/javascript">
$('.list-group-item').on('click', function () {
    var href = $(this).attr("href");
    var arr = href.split('path=');
    var cat_id = arr[1];
    //alert("hai");
    $.ajax({
        type: 'post',
        url: 'index.php?route=ajax/ajaxcat/index',
        data: format_data,
        dataType: 'json',
        success: function (json) {
            if (json['success']) {
                //$('#messages').html(json['success']);
                alert(json['success']);
            }
        }
    });
});
</script>

Here is my php code:

 <?php
  class ControllerAjaxAjaxcat extends Controller {
    function index() {
      $json['success'] = 'This is the returned results color_adjust.php';
      $this->response->setOutput(json_encode($json));
    } 
  }
 ?>

I don't know what is wrong with that code it cant return the value.

Joe
  • 4,877
  • 5
  • 30
  • 51
James
  • 29
  • 6
  • Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Andreas Jul 21 '17 at 11:56
  • " it wont work " is not an error message or problem description. Please clearly describe any errors that you get (either on the server, or in your browser's console) and/or any unexpected behaviour that you experience (as opposed to what you expected to happen). – ADyson Jul 21 '17 at 14:52
  • $json['success'] did not return in alert function – James Jul 22 '17 at 03:57

0 Answers0