Welcome Guest, Not a member yet? Register   Sign In
Comment system with jQuery and problem it!!!
#7

[eluser]titandj[/eluser]
Hi!


You have some inconsistencies in your code...

In Jquery:

Although it can be omitted, and the ajax function should detect the type of data returned, is good practice to declare the type of data expected in response:

Code:
$.ajax({
  type: 'POST',
  url: url,
  data: data,
  success: success,
  dataType: 'json'   // <----you omit this statement
});

In Controller:

do not understand you want to do with this function into the controller, I guess it is a debug of the data received...

In Model:

You should not perform an insert, without validating the data from the client, either because they may have brought a wrong or no data.

I recommend that collect and validate data in the controller

If you see your role in codeigniter is working properly, set default data and calls the same as any other page in the browser:

CONTROLLER EXAMPLE:

Code:
function comment_insert()
    {
    $arr_data = array();
    $arr_data['entry_id'] = $this->input->post('entry_id', TRUE);
    $arr_data['comment_name'] = strtolower($this->input->post('comment_name', TRUE));
    $arr_data['comment_email'] = $this->input->post('comment_email', TRUE);
    $arr_data['comment_body'] = $this->input->post('comment_body', TRUE);
    $arr_data['comment_date'] = jgmdate("j F Y");

    //Test data
    $arr_data['entry_id'] = 1;
    $arr_data['comment_name'] = 'One name';
    $arr_data['comment_email'] = '[email protected]';
    $arr_data['comment_body'] = 'One body';
    $arr_data['comment_date'] = jgmdate("j F Y");

    if($this->blog_model->comment_insert($arr_data)){
      echo json_encode(array('message' => 'all done!'));
    }else{
      echo json_encode(array('message' => 'not work!'));
    }
    
    }

Call the function in your application in a browser:

http://mydomain.com/index.php/myControll...ent_insert

If all goes well, and performs the insert will see:

{"message":"all done!"}

Or the specific PHP error or the json error:

{"message":"not work!"}

In this case, the error is in the data inseción.


test and comments!


Messages In This Thread
Comment system with jQuery and problem it!!! - by El Forum - 06-27-2011, 11:07 PM
Comment system with jQuery and problem it!!! - by El Forum - 06-28-2011, 04:54 PM
Comment system with jQuery and problem it!!! - by El Forum - 06-30-2011, 01:54 AM
Comment system with jQuery and problem it!!! - by El Forum - 06-30-2011, 08:45 AM
Comment system with jQuery and problem it!!! - by El Forum - 06-30-2011, 08:54 AM
Comment system with jQuery and problem it!!! - by El Forum - 06-30-2011, 09:14 PM
Comment system with jQuery and problem it!!! - by El Forum - 07-02-2011, 12:42 PM



Theme © iAndrew 2016 - Forum software by © MyBB