Edit: Cant change the headline. it should be Cross-Origin Request Blocked, in Firefox. On Chrome it's good.
===================
Hi;
I use ajax to update db.
It sends the form data and updates the DB well, however, the response doesn't work. Inspector says:
It's open you can see it live ===> here <===
What am I doing wrong?
Thanks
Code:
function submit_form(form_id, form_box)
{
$("#"+form_id).submit(function(e)
{
var url = '<?php echo base_url('plc_template_update');?>';
$.ajax({
type: "POST",
url: url,
data: $("#"+form_id).serialize() + '&item_type=' + '<?php echo $item_type;?>' + '&item_id=' + '<?php echo $item_id;?>',
success: function(data)
{
$("#"+form_box).addClass('hide-me');
$("#success").removeClass('hide-me');
window.setTimeout(function(){
$("#success").addClass('hide-me');
}, 1000);
}
});
e.preventDefault();
});
}
PHP Code:
class Plc_template_update extends CI_Controller {
public function index()
{
if(!isset($_POST['item_id']) || !ctype_digit($_POST['item_id']))
{
exit();
}
if($_POST['item_type']=='plc')
{
//Uncomment when tests are over
// if(!$this->plc_library->is_this_plc_owner($_POST['item_id']))
// {
// exit();
// }
}
$data = array();
foreach($_POST as $val=>$row)
{
if($val!='item_id' && $val!='item_type' )
{
$data[$val]=$row;
}
}
$this->db->where('id', $_POST['id']);
$this->db->update('launch_page_elements', $data);
http_response_code(200);
}
}