JQuery’s mythical being strategies extremely created straightforward to post information a knowledge an information and come back that data while not refreshing the page. We are able to apply this jQuery mythical being post in CodeIgniter still. Before continuing any we tend to take into account that you just square measure a touch at home with CodeIgniter PHP framework. With the assistance of Associate in Nursing example, you'll find out how to post information to a controller victimization the CodeIgniter jQuery mythical being methodology.
Friend's if you don't know how to install Codeigniter in localhost or sever read my last post click this link -https://www.softwarequery.com/2018/02/how-to-install-codeigniter-on-localhost.html
Step-1. We create an HTML code in index.php
<!DOCTYPE html>
<html>
<head>
<title>Registration | SoftwareQuery</title>
</head>
<body>
<body>
<form id="form" method="post">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="name" id="name"/>
</tr>
<tr>
<td>Email:</td>
<td><input type="email" name="email" id="email">
</tr>
<tr>
<td colspan="2">
<input type="button" name"submit" id="submit">
</td>
</tr>
</table>
<span id="p1" style="display:none;"> Success</span>
<span id="p2" style="display:none;">Error</span>
</form>
</body>
</html>
-----------------------------------------------JQuery Code-------------------------------------------
Step- 2. Search html code ctrl+F this tag </head> and put the script.
<script src="https://ajax.googleapis.com/ajax/libs/dojo/1.13.0/dojo/dojo.js"></script>
-----------------------------------------<Script>...................................................................................
Step-3. Go got HTML code and press button ctrl+f search </body> tag put this script.
<script>$(function(){
$('#p1').hide();
$('#p2').hide();
$("#submit").click(function(){
var empty = false;
$('#name').each(function() {
if ($(this).val().length == 0) {
empty = true;
}
});
if (empty) {
$('#p2').fadeIn();
$("#p2").delay(2000).fadeOut();
}
else {
var empty = false;
$('#email').each(function() {
if ($(this).val().length == 0) {
empty = true;
}
});
if (empty) {
$('#p2').fadeIn();
$("#p2").delay(2000).fadeOut();
}
else{
var name = $("input[name=name]").val();
var email = $("input[name=email]").val();
$.ajax({
type: "POST",
url: "<?php echo base_url('controoler_name/insert/'); ?>",
data: {name:name,email:email},
success: function() {
$('#p1').fadeIn();
$("#p1").delay(2000).fadeOut();
$('#form').find("input[name=name], input[name=email]").val("");
}
})
}
})
</script>
----------------------------------------------Create Model---------------------------------------------
Step-4. Go to Model Folder and open create new model file save any name the put this code. After put, code go to the browser and type localhost/phpmyadmin create new database name then make two field email, name.
function insert($name,$email)
{
$data = array(
'column_name'=> $name,
'coulmn_name_email' => $email
);
$this->db->insert('table_name',$data);
return true;
}
.............................................................Create Controller...................................................................
Step-5. Go to controller Folder and open new model file save any name the put this code.
function insert(){
$name= $this->input->post('cname');
$email= $this->input->post('cemail');
if(($cname=='')||($cemail=='')){
echo 'error';
}else
$data = $this->model->insert($name,$email);
if($data == 'true'){
echo 'success';
else
{
echo 'error';
}
}
}
I loνed aѕ muсh as you will recеive carried out right herе.
ReplyDeleteThe sкetch is attractіve, your authored subject matter stylish.
nonetheless, you command get got an impatience over that you wish be ⅾelivering the following.
unwell unquestionably come fuгther formerly again as еxaсtly
the same nearly very often insidе caѕe you
shield this increase.
helpful resources : How To Learn To Password Ⲣrotect Folder In 1 Hour
Thanku buddy
DeleteԜrite more, thats all I have to say. Literally, it seems as though you relied on the video to make your point.
ReplyDeleteYou definitely know what ʏoure talking about, why ᴡaste your intelligence on just posting vіdeoѕ to your blog
whеn you could be giving us something enlightening to read?
more : Loсk Fiⅼes It: Herе’s How
My brother recommended I might liкe this blog. He was totallу right.
ReplyDeleteThis p᧐st actually made my day. You can not іmagine
just how much time I had spent for this іnformаtion!
Thanks!
go to tһis site : How To Learn To Pasѕword Protect Folⅾer Just 15 Minutes A Day
555
ReplyDelete