3

Im using codeigniter to load a view. This view has a button to open a modal and in this modal i must load a method from another controller. To do this, i'm using ajax passing data by POST.

This is my ajax:

$('#modalView').on('shown.bs.modal', function (e){
    $.ajax({
        method: "POST",
        url: "../ci_visualizacao/comparaGrafico",
        crossDomain: true,
        data: { sensor: eqrel, ajax: "1" }
    }).done(function( data ) {
        $(".modal-body").html(data);
        $('.modal-body div:not(#chart)').hide();
    });
});

This view (comparaGrafico) has a javascript to initiate a highstock chart.

So the problem is that i'm getting this error when loading the ajax:

XMLHttpRequest cannot load javascript:;. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.

The entire page loads but not the javascript part.

And it is in same origin! or not? Is there another way to do this, or a solution to this problem?

thanks

Hubertokf
  • 308
  • 1
  • 4
  • 12

2 Answers2

0

url should be

url: "<?php echo base_url() ?>ci_visualizacao/comparaGrafico"

to use base_url()

In config.php

$config['base_url'] = '';

And in autoload.php

$autoload['helper'] = array('url');
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
0

try adding this in constructor once.

public function __construct()
{
    header('Access-Control-Allow-Origin: *');
    header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
    parent::__construct();
}
Niranjan N Raju
  • 12,047
  • 4
  • 22
  • 41