Welcome Guest, Not a member yet? Register   Sign In
Ajax callback fails (but used to work)
#1

[eluser]Ivoo[/eluser]
OK, this is weird. I have an jQuery ajax call-back to my CodeIgniter controller. A month ago, this worked fine. But now it stopped working. The problem is that the controller-function is not reached.

Also, it is not a routing problem. When I manually point my browser to the my callback function (repository/asm), it works fine.

I suspect that I unknowingly changed some configuration, or some setting. But what?

Any suggestions?

jQuery:
Code:
$.ajax({
   type: 'POST',
   url: "repository/asm",
   async: false,
   data: { mediaID: mediaID },
   success: function(jsonData){
    data = $.parseJSON(jsonData);
    $('#innerImageFrame img').attr("src",data.uri);
    $('#titleFrame').html(data.titleInArchive);
    $('#commentFrame').html(data.commentInArchive);
    $('#yearselect').val(data.yearselect);
    $('#monthselect').val(data.monthselect);
    $('#dayselect').val(data.dayselect);
    $('#starRating').raty('start', data.starRating);
   }
  });


CodeIgniter:
Code:
<?php // if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Repository extends CI_Controller {

public function __construct()
{
  
  parent::__construct();
  $this->load->helper('url');
  $this->load->model('ifm_media_model');
  // $this->load->model('news_model');
}


  public function asm()
  {
  log_message('debug', '*** asm (ajax callback) (repository.php) was called');

// .. other code, but the above message is already never logged
#2

[eluser]InsiteFX[/eluser]
Try:
Code:
url: <?php echo base_url()?>+"repository/asm",
#3

[eluser]Ivoo[/eluser]
Thanks for looking at this. I did not know you could create php-islands in jQuery like you can in HTML. Thanks for showing that.

Sadly, it does not resolve the problem. Further investigations taught me that the post-request results in

"NetworkError: 500 Internal Server Error - http://www.essential-strategy.com/reposi...sitory/asm"

I am now trying to get support from my hoster (Dreamhost). They are usually good with support, so hopefully that will point me in the right direction.

#4

[eluser]Ivoo[/eluser]
resolved!

It turns out that this problem (ajax callback results in 500 internal server error) can be caused by the

|--------------------------------------------------------------------------
| Cross Site Request Forgery
|--------------------------------------------------------------------------
| Enables a CSRF cookie token to be set.

The problem can be worked around by setting:

Code:
$config['csrf_protection'] = FALSE;

in CodeIgniter's /application/config/config.php file.

Don't ask me why, because I do not know. I just found an off-hand remark that pointed me in the right direction here.
#5

[eluser]CroNiX[/eluser]
Or, you can send the csrf token along with your form...




Theme © iAndrew 2016 - Forum software by © MyBB