1

im making and update in mysql table when button click, the problem is ajax jquery not working sometimes. It works fine and somehow after x attempts it stop working and stars cancelling my pettitions

my jquery code:

$.ajax({
  type:'GET',
  url: 'php/updateCosto.php',
  data:{
    obrero: $obrero,
    fechai: $fechaa,
    fechaf: $fechab,
    costo: $costoS,
  },
  success: function(result){
    if (result == 1) {
      alert('Registro Actualizado');
      location.reload(true);
    }else {
      console.log("no actualizado entrada");
      alert('Registro No Actualizado');
      location.reload(true);
    }
  }

}); // fin del ajax

the php one:

    <?php
include('../db/conn.php');


$maestro      = mysql_real_escape_string($_GET['obrero']);
$costosemanal = mysql_real_escape_string($_GET['costo']);
$fechai       = mysql_real_escape_string($_GET['fechai']);
$fechaf       = mysql_real_escape_string($_GET['fechaf']);

  $update = "UPDATE tbl_costos
             SET costo_semanal = '$costosemanal'
             WHERE fechai = '$fechai'
             AND fechaf ='$fechaf'
             AND obrero = '$maestro'";

$result = mysql_query($update);

$rows = mysql_affected_rows();

echo ($rows);

mysql_free_result($result);
?>

the problem is after x number of attempts the success part of ajax object is not being used and im getting the STATUS (canceled) from network.

I dont know if it is an issue of CORS AJAX pettition or something!!

glombana
  • 11
  • 1
  • 1
    [Your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Jay Blanchard Sep 23 '15 at 21:49
  • If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Sep 23 '15 at 21:49
  • Have you watched the request / response in the browser's console? – Jay Blanchard Sep 23 '15 at 21:49
  • yes! on the browser console i get the status Cancelled, and sometimes is OK, even when i send the same info! @JayBlanchard – glombana Sep 23 '15 at 21:55

0 Answers0