CodeIgniter Forums
Facing problem while using ajax with codeigniter 2.0 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Facing problem while using ajax with codeigniter 2.0 (/showthread.php?tid=39411)



Facing problem while using ajax with codeigniter 2.0 - El Forum - 03-10-2011

[eluser]manishchndk[/eluser]
In config.php i created a variable $config['base_url'] = 'http://localhost/car/';
In Controller folder i created "user" folder and one default controller "welcome.php"
In View folder i created folder "user" folder and view file "welcome_message.php"
when i am running this on browser, default controller loads "new_user.php" from view/user and there i written a code for ajax given below

//loaded all the necessary file required to execute ajax code
[removed]
$(function()
{
$("#check_availability").click(function()
{
var temp = "ABC";
$.ajax
({
type: "POST",
url: '<?php echo base_url(); ?>application/views/welcome_message.php',
data: "login_name="+temp,
sucess: function()
{
alert("hello");
}
});
});
});
[removed]

welcome_message.php
<?php
$name=$_POST['login_name'];
echo $name;
?>

but this code is not working for me, can anybody suggest what to do and where i am making mistake


Facing problem while using ajax with codeigniter 2.0 - El Forum - 03-10-2011

[eluser]LuckyFella73[/eluser]
Code:
url: ‘<?php echo base_url(); ?>application/views/welcome_message.php’,

You have to send the post data to a controller instead of sending to a view
like you are doing.


Facing problem while using ajax with codeigniter 2.0 - El Forum - 03-10-2011

[eluser]Rok Biderman[/eluser]
You'll possibly encounter further difficulties with csrf protection. If you do, make form with form_open and then include hidden csrf field into ajax request as well, or try turning off csrf protection off in config for development purposes.