Welcome Guest, Not a member yet? Register   Sign In
Updating my news post (with jquery/Ajax)
#1

[eluser]DynamiteN[/eluser]
I've been trying to get this to work, searched here and google with no luck
so i thought i gave it a shot telling my problems to you guys

anyways, i have a model, controller, and a view all setup
When i try to update this news post without all the ajax and stuff it works just fine
but if i try to use the ajax it wont work
i watched this tutorials earlier
http://www.weblee.co.uk/2009/06/07/simpl...er-part-1/
but i dont really know much about coding jquery and such
and in those tutorial he never shows how to do when working with a db
anyway
here is my controller:
Code:
function EditNewsPost() {
/*See details of a news post
Okey so THIS is the page/function i go to,so i see all the current data of the news post
and i show them in input fields
*/
    //if post is not submitted
    if($this->input->post('submit') == FALSE) {
            
    $nid = $this->uri->segment(4);
    $get = $this->admin_news_model->GetOneNews($nid);
    foreach($get as $news){
    $data['newspost'] = $news;
    }
    $data['page_title'] = 'View News Details';
    $this->load->view('admin/edit_news', $data);
    }else{
    $this->UpdateNews();
    }
}

    
function UpdateNews() {
/*
This is the function i am sent to after clicking submit
*/
if($this->input->post('submit') == TRUE){
$nid = $this->uri->segment(4);
$this->form_validation->set_rules('newstitle', 'News Title', 'required|trim');
$this->form_validation->set_rules('newsauthor', 'News Author', 'required|trim');
$this->form_validation->set_rules('newscontent', 'News Content', 'required|trim');
$this->form_validation->set_rules('news_date', 'News Date', 'required');

$newstitle = $this->input->post('newstitle');
$newsauthor =  $this->input->post('newsauthor');
$newscontent = $this->input->post('newscontent');
$news_date =  $this->input->post('news_date');
            
$data = array(
    'title'   => $newstitle,
    'content' => $newscontent,
    'author' => $newsauthor,
    'news_date' => $news_date
            );
            
    if($this->form_validation->run() == FALSE) {
    echo validation_errors();
    }else{
    $this->admin_news_model->UpdateNews($data, $nid);
    }

}else{
//if the submit is false
  $this->editnewspost();

}
            
}
And here is the view:
Code:
<?php $this->load->view('admin/header'); ?>


<div id="edit_news">
<div id="busy" style="display:none">Processing Form <img src="&lt;?php base_url(); ?&gt;/img/js/ajax-loader.gif" /></div>
<br/>
<div id="errors">&lt;?php echo validation_errors(); ?&gt;</div>

&lt;?php $form = array('id' => 'news_form');?&gt;

&lt;?php echo form_open("admin/admin_news/updatenews/$newspost->id", $form); ?&gt;

<p>Title: &lt;?php echo form_input('newstitle', $newspost->title); ?&gt;</p>

<p>Author: &lt;?php echo form_input('newsauthor', $newspost->author); ?&gt;</p><br/>

<p>Content: </p>&lt;?php echo form_textarea('newscontent', $newspost->content); ?&gt;<br/>
<br/>
<p>News Date: &lt;?php echo form_input('news_date', $newspost->news_date); ?&gt;</p><br/>

<br/>
&lt;?php echo form_submit('submit', 'Edit Post');?&gt;
&lt;?php echo form_close(); ?&gt;
</div>

&lt;?php $this->load->view('admin/footer'); ?&gt;

ALL this code actually works Smile
but if i where to add this code:
Code:
// Functon to Show out Busy Div
function showBusy(){
    $('#busy').show('slow');
}

// function to process form response
function processForm(html){

        $('#errors').hide('slow');
        
        window.setTimeout( function(){
            
            $('#busy').hide('slow');
            
        
            if(parseFloat(html)){
                 $('#news_form').after('Thank you for submitting');
                 $('#news_form').hide('slow');
             }else{
                 $('#errors').html(html).show('slow');
             }
            
         }, 3000);
    
}


$(document).ready(function() {

    // $.AJAX Example Request
    $('#news_form').submit(function(eve){
        eve.preventDefault();
        
        $.ajax({
            url: "/admin/admin_news/editnewspost/",
            type: "POST",
            dataType: "html",
            data: $('#news_form').serialize(),
            beforeSend: function(){
                showBusy();
            },
    
              success: function(html) {
                processForm(html);
             }
        });
        

    });

});

It wont work, and i dont know how to do this
i've been trying to go forward from that tutorial but i just cant get it to work
Plz, any help is highly appreciated

P.S im sure all my code could use some cleaning up Smile


Messages In This Thread
Updating my news post (with jquery/Ajax) - by El Forum - 04-11-2010, 08:42 AM
Updating my news post (with jquery/Ajax) - by El Forum - 04-11-2010, 10:46 AM
Updating my news post (with jquery/Ajax) - by El Forum - 04-11-2010, 10:50 AM
Updating my news post (with jquery/Ajax) - by El Forum - 04-11-2010, 11:12 AM
Updating my news post (with jquery/Ajax) - by El Forum - 04-11-2010, 11:16 AM
Updating my news post (with jquery/Ajax) - by El Forum - 04-11-2010, 11:23 AM
Updating my news post (with jquery/Ajax) - by El Forum - 04-11-2010, 11:27 AM
Updating my news post (with jquery/Ajax) - by El Forum - 04-11-2010, 11:43 AM
Updating my news post (with jquery/Ajax) - by El Forum - 04-11-2010, 01:12 PM
Updating my news post (with jquery/Ajax) - by El Forum - 04-11-2010, 03:21 PM
Updating my news post (with jquery/Ajax) - by El Forum - 04-11-2010, 04:03 PM
Updating my news post (with jquery/Ajax) - by El Forum - 04-11-2010, 04:18 PM
Updating my news post (with jquery/Ajax) - by El Forum - 04-11-2010, 06:34 PM
Updating my news post (with jquery/Ajax) - by El Forum - 04-11-2010, 06:54 PM
Updating my news post (with jquery/Ajax) - by El Forum - 04-11-2010, 07:03 PM
Updating my news post (with jquery/Ajax) - by El Forum - 04-11-2010, 07:10 PM
Updating my news post (with jquery/Ajax) - by El Forum - 04-11-2010, 07:43 PM
Updating my news post (with jquery/Ajax) - by El Forum - 04-11-2010, 07:57 PM
Updating my news post (with jquery/Ajax) - by El Forum - 04-11-2010, 08:33 PM
Updating my news post (with jquery/Ajax) - by El Forum - 04-12-2010, 07:55 AM
Updating my news post (with jquery/Ajax) - by El Forum - 04-12-2010, 08:03 AM
Updating my news post (with jquery/Ajax) - by El Forum - 04-12-2010, 08:22 AM
Updating my news post (with jquery/Ajax) - by El Forum - 04-12-2010, 10:12 AM
Updating my news post (with jquery/Ajax) - by El Forum - 04-12-2010, 01:24 PM
Updating my news post (with jquery/Ajax) - by El Forum - 04-12-2010, 01:35 PM
Updating my news post (with jquery/Ajax) - by El Forum - 04-12-2010, 01:43 PM



Theme © iAndrew 2016 - Forum software by © MyBB