I want to dynamically parse RSS feeds.
I have a select list and I would like to send a value (id) to the controller with ajax.
and after, I want to parse RSS feeds corresponding to the id
My Controller home.php :
function view($type = NULL)
{
$data = array();
$this->load->model('flux_model');
if ($type == "ajax") {// load ajax view
$flux = $this->flux_model->get_one_flux($this->input->post('id'));// ajax id
$flux2 = $flux[0]->url_flux;
$xml = new SimpleXMLElement($flux2, NULL, TRUE);
//my foreach
$this->load->view('messages_list', $data);
}
else{ // load the default view
$nb_min = 0;
$nb_max = 7;
$nombre = mt_rand($nb_min,$nb_max);
$flux = $this->flux_model->get_one_flux($nombre);
$flux2 = $flux[0]->url_flux;
$xml = new SimpleXMLElement($flux2, NULL, TRUE);
//my foreach
$this->load->view('default', $data);
}
}
Ajax script :
$("#myform1 #rss").change(function(){
var msg = $('#myform1 #rss').val();
$.post("<?= site_url('home/view/ajax') ?>", {id: msg}, function() {
$('#main').load("<?= site_url('home/view/ajax') ?>");
$('##myform1 #country').val('');
});
});
view default works, I parse an RSS feed randomly
but with the ajax view, I have this error:
Message: SimpleXMLElement::__construct(): I/O warning : failed to load external entity “”
it looks like I do not get the id?! ajax problem?
I think your issue is with
Because many sites’ configurations will prevent cross-site Ajax requests (See XSS), your $.post will be prevented. Instead, try something like:
Example:
In your JavaScript:
And in your controllers/ajax.php file:
I hope this helps!