我正在使用 codeigniter 加载 View 。该 View 有一个用于打开模式的按钮,在该模式中我必须从另一个 Controller 加载方法。为此,我使用 ajax 通过 POST 传递数据。
这是我的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();
});
});
此 View (comparaGrafico) 有一个 JavaScript 来启动 highstock 图表。
所以问题是我在加载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/.
加载整个页面,但不加载 JavaScript 部分。
而且是同源的!或不? 有其他方法可以做到这一点,或者解决这个问题吗?
谢谢
最佳答案
网址应该是
url: "<?php echo base_url() ?>ci_visualizacao/comparaGrafico"
使用base_url()
在config.php
$config['base_url'] = '';
并在autoload.php
$autoload['helper'] = array('url');
关于javascript - Jquery ajax 到 codeigniter 上的另一个 Controller /方法出现跨源问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33116733/