Welcome Guest, Not a member yet? Register   Sign In
500 error when Post data through ajax when csrf is true
#1

[eluser]bleu[/eluser]
I am using the below code to get values through ajax.
When I disable csrf it posts properly , but when I turn csrf true it gives me 500 error

Any Ideas as to how I can solve this?


Code:
[removed]
$(document).ready(function(){
  $("#btn").click(function () {
   $("#ur").css('display:none;');
   $.ajax({


    type: "POST",
    data: "data=" + $("#Code").val()+",csrf_token_name="+  $("input[name=csrf_test_name]").val()  ,
    url: "http://www.xyz.com/getit/Click",
    success: function(msg){
     $("#content").html(msg)
    }
   });
  });
});
[removed]
#2

[eluser]InsiteFX[/eluser]
Error 500 is a server error!
#3

[eluser]bleu[/eluser]
[quote author="InsiteFX" date="1333614521"]Error 500 is a server error!
[/quote]

I find
Code:
500 Internal Server Error
through firebug when csrf is true.

When csrf is off there is no error
#4

[eluser]InsiteFX[/eluser]
Try reading this:

CodeIgniter CSRF Protection
#5

[eluser]bleu[/eluser]
[quote author="bleu" date="1333611197"]I am using the below code to get values through ajax.
When I disable csrf it posts properly , but when I turn csrf true it gives me 500 error

Any Ideas as to how I can solve this?


Code:
[removed]
$(document).ready(function(){
  $("#btn").click(function () {
   $("#ur").css('display:none;');
   $.ajax({


    type: "POST",
    data: "data=" + $("#Code").val()+",csrf_token_name="+  $("input[name=csrf_test_name]").val()  ,
    url: "http://www.xyz.com/getit/Click",
    success: function(msg){
     $("#content").html(msg)
    }
   });
  });
});
[removed]
[/quote]


I did it like this

Code:
$.ajax({  
        type: "POST",
        url:  "http://www.xyz.com/getit/Click",

        data: "data=" + $("#Code").val()+"&csrf;_test_name="+  $("input[name=csrf_test_name]").val()  ,
  
     //   data: form_data,
        success: function(data) {
            alert('it worked');
        }
    });
});

I added &csrf;_test_name instead of ,csrf_test_name








Theme © iAndrew 2016 - Forum software by © MyBB