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

[eluser]DynamiteN[/eluser]
Okey, so now i have edited a little in my files and dont really know what to do next
instead of having the java in a seperat file called .js
i now moved it to the view file (edit_news.php) this is the file where i submit the data
this is the php and java code in view file:
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;

[removed]

// 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/UpdateNews/",
            type: "POST",
            dataType: "html",
            data: $('#news_form').serialize(),
            beforeSend: function(){
                showBusy();
            },
    
              success: function(html) {
                processForm(html);
             }
        });
        

    });
});
            
  // Load jQuery
google.load("jquery", "1.4.2");
[removed]

<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;
When this linesad this:
Code:
url: "/admin/admin_news/UpdateNews/",
the whole page got fucked after submitting
now it is like this:
Code:
url: "/admin/admin_news/UpdateNews/",
And then it wont get fucked up on page

this is the controller right now:
Code:
function EditNewsPost() {
//See details of a news post
    
            //if post is not submitted
            if($this->input->post('submit') == FALSE) {
            
            $nid = $this->uri->segment(4);
                $get = $this->admin_news_model->GetOneNews($nid);
                if($get){
                $data['newspost'] = $get;
                }else{ /*Do nothing*/ }
            $data['page_title'] = 'View News Details';
            $this->load->view('admin/edit_news', $data);
            }else{
                $this->UpdateNews();
            }    
}

function UpdateNews() {
if(IS_AJAX) {
    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{
            echo "News not updated";
            }
}else{
echo "No Direct Access";
}
}




now when i press submit that function (busy) that shows a rotating icon shows up as it's suppose to adn then i wait for the news updated line but i get the "news not updated"
and i dont know why, not getting any errors either in firebug

EDIT1:
P.S IF i submit everything without the java/ajax code it gets updated :/


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