I am using CodeIgniter and jQuery .ajax function to send data from my view to my controller and update my database. Here is the problem, I use form_open()
to generate code for my form, I need to use this so that in my controller I can use form validation library. Form validation library only works if you use "POST" method. But nevermind all that.
If I would use normal submit button to submit my form to controller everything would work fine. However I don't know how to use ajax in this case, what should I put in $.ajax({ url: ??? });
I need ajax to post the data to controller exactly like normal submit button would in my form. I think that in my case ajax function doesn't send request to controller like the regular submit button would.
Here is my form (I ommited inline styles and classes by purpose):
HTML
<div class="" style="">
<h1 id="header" class="">Login/Register</h1>
<?php echo form_open('users/sportappregister', 'data-ajax="false"'); ?>
<div style=""><input id="email" type="text" name="email" value="email" style=""></div>
<div style=""><input id="pass" type="text" name="password" value="password" style=""></div>
<div style="" class=""><img class="" style="" src="<?php echo img_path(); ?>ikone/fb_login_icon.png" />Login with Facebook</div>
<div id="send" style="" class=""><input type="submit"> Submit </div>
<div id="cancel" style="" class=""> Cancel </div>
</form>
</div>
jQuery
document ready etc...
$("#send").click(function() {
$.ajax({
url: "/public/index.php/users/sportappregister",
type: "POST",
data: {email: $("#email").val(), password: $("#pass").val()},
dataType: "text",
success: function(msg){$("#header").css({"color":"red"}).html(msg);}
});
I don't need to show you my controller as everything works fine there, problem is only here in my form page. Data isn't posted to controller correctly.