JQuery returns json object with 404

I am completely new to the whole jQuery / JSON thing, but thought I would give it away. The idea is that I send data to a PHP script and then return a JSON object. This works fine on my localhost, but on the Firebug web server it shows that the JSON object is returning, but I also get a 404 error.

Any ideas I might be wrong about?

Javascript -

    $(".vote").click(function(){
 $('#graph').empty();
 var area = $(this).attr("id");
 $.ajax({
  dataType: "json",
  type: "POST",
  url: "<?php echo base_url(); ?>home/vote",
  cache: false,
  data: "area="+ area,
  success: function(json){

   arrayOfData = new Array(
    [json.science_graph,'Science','#009999'],
    [json.maths_graph,'Maths','#FF6600'],
    [json.ict_graph,'ICT','#FF0000'],
    [json.mfl_graph,'MFL','#FFCC00'],
    [json.dt_graph,'Design Technology','#33CC00'],
    [json.other_graph,'Other Events','#003399']
   ); 
   $('#graph').jqBarGraph({ data: arrayOfData, barSpace: 5, width: 430 });

  }
 }); 
});

PHP -

 if ($vote == true)
   {
    $poll = $this->ts_model->graph_poll();

    list($maths, $science, $ict, $dt, $mfl, $other) = $poll;

    echo "{";
    echo "\"science_graph\":\"".$science."\",";
    echo "\"ict_graph\":\"".$ict."\",";
    echo "\"dt_graph\":\"".$dt."\",";
    echo "\"other_graph\":\"".$other."\",";
    echo "\"mfl_graph\":\"".$mfl."\",";
    echo "\"maths_graph\":\"".$maths."\"";
    echo "}";
   }

Thanks in advance.

+3
source share
3 answers

What is the ".vote"? I suggest modifying this click handler to have

return false;

. ( ) , ".vote" - <a>, "click" , . false, .

0

json- 404, , , , . URL-, , , . , script.

0

, -. , , 404 - htaccess:

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>
0

Source: https://habr.com/ru/post/1751006/


All Articles