Welcome Guest, Not a member yet? Register   Sign In
Handling errors differently when calling from Ajax
#2

[eluser]jonez[/eluser]
I solved this using JavaScript by creating a conduit system for all AJAX calls. Instead of calling $.ajax you call a method on your module and pass in the normal params and a callback function. You wrap the callback param in another function that attempts to json decode the server response. If the decode fails you throw an error. If it succeeds you pass the decoded object to the original callback. This requires every AJAX response to be in JSON, so if you send back HTML blobs you can't send raw HTML you have to wrap it in a JSON object. Ideally you should only send data back from AJAX and compile the view on the client.

Also you never want to run un-escaped queries like that use the db->update method or parametrized queries.
Code:
$this->db->where( 'account_id', $accountId );
$this->db->update( 't_accounts', array( 'bank_balance_am' => $amt ) );

//or

$query = $this->db->query("
    UPDATE t_accounts
    SET  bank_balance_am = ?
    WHERE account_id = ?
  ", array($amt, $accountId));


Messages In This Thread
Handling errors differently when calling from Ajax - by El Forum - 12-27-2013, 01:21 PM
Handling errors differently when calling from Ajax - by El Forum - 12-27-2013, 02:05 PM
Handling errors differently when calling from Ajax - by El Forum - 12-27-2013, 02:41 PM
Handling errors differently when calling from Ajax - by El Forum - 12-27-2013, 03:58 PM



Theme © iAndrew 2016 - Forum software by © MyBB