JavaScript Jquery ajax to another controller/method on codeigniter getting Cross origin issue jquery ajax cross domain,jquery.ajax-cross-origin.min.js,

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

Answer:1

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');
Answer:2

I'm trying to sort the JSON by release date, by random, by alphabetical order or by popularity. I'm not sure if the answer is on here, I checked and I can't seem to figure out if it's for me. My ...

I'm trying to sort the JSON by release date, by random, by alphabetical order or by popularity. I'm not sure if the answer is on here, I checked and I can't seem to figure out if it's for me. My ...

I try to create a new pieces page, kind of a blog style in apostrophe cms. I have trainings, trainings-widgets and trainings-pages folders. I registered them all in app.js; pieces by themselves and ...

I try to create a new pieces page, kind of a blog style in apostrophe cms. I have trainings, trainings-widgets and trainings-pages folders. I registered them all in app.js; pieces by themselves and ...

  1. apostrophe pieces pages

I am passing a state as props in child component, but child is updating previous props to its state. For example: I am passing state = a, then state is updated to state = b. Child will update it as ...

I am passing a state as props in child component, but child is updating previous props to its state. For example: I am passing state = a, then state is updated to state = b. Child will update it as ...

I have the below line of java script, which aims to split a string and replace the value at the splitted section with the new value. I appreciate this could be done with a 2-dimensional array, but I ...

I have the below line of java script, which aims to split a string and replace the value at the splitted section with the new value. I appreciate this could be done with a 2-dimensional array, but I ...