Hi all,

I had created a function updateprintingqc() that work like this

  1. user will click on a clickable button to update the data
    2.when user click on OK,the dummy data will be create based on the main data shown in below image's link
    https://drive.google.com/file/d/0B46VQHVMeBTNMzVodDRxZEw3dGs/view?usp=sharing

When the user click the button for the 1st time,the function work fine.But when the user click on the button for the 2nd time,error occur.

Here's my coding in javascript

function updateprintingqc(this_, idschedule,idmsul,articleno,part_name,remain) {

  var conf = confirm("Are you choose to Update this Row of Record?");
    if (conf == true) {
        var url = "msp/updateqc?id=" + idschedule + "&idmsul=" + idmsul+"&articleno=" + articleno + "&part_name=" + part_name +"&remain="+remain ;
        $.ajax({
            type    : "get",
            url     : url,

            success : function(data) {
                var obj = jQuery.parseJSON(data);

                if (obj.status == 'Complete') {
                    displaymsg('Update Record', obj.msg);
                    oTable.fnStandingRedraw();
                }
            }
        });
    }
}

and here my code in php :

function updateqc() {
     $id        = $this -> input -> get('id', TRUE);
     $idmsul    = $this -> input -> get("idmsul");
     $articleno = $this -> input -> get("articleno");   
     $part_name = $this -> input -> get("part_name");   
     $remain       = $this -> input -> get("remain");
     $checking  = "select * from sindi_printing_qc_log where type='dummy'and idschedule='{$id}' ";

        $checkresult = count($this -> global_model -> query($checking) -> row());

        if($checkresult > 0 ){
            echo "Dummy already exist.";
        } else {
            $temp = array(
                "printing_log"=> 0,
                "idmsul"      => $idmsul,
                "articleno"   => $articleno,
                "part_name"   => $part_name,
                "qty"         => $remain,
                "pass"        => $remain,
                "reject"      => 0,
                "repaired"    => 0,
                "replaced"     => 0,
                "missing"     => 0,
                "procedure"   => 2,
                "addby"     => "LukeSkyWalker",
                "isvalid"     => 1,
                "updateby"    => "LukeSkyWalker",
                "updatedate" => date("y-m-d H:i:s"),
                "idschedule"  => $id,
                "type" => "Dummy"

            );
            $this -> db -> insert("sindi_printing_qc_log",$temp);
            $msg  = array('status' => 'Complete', 'msg' => 'Update Record ' . $id . ' Completed !');
            echo json_encode($msg);
        }
  }

Can anybody assists me for this problem??

Thanks.

Recommended Answers

All 2 Replies

Hi,
Please change:

if($checkresult > 0 ){
    echo "Dummy already exist.";
}

to:

if($checkresult > 0 ){
   $msg  = array('message' => 'Dummy already exists !');
   echo json_encode($msg);
}

You're expecting the server response to always be a json object, so even for errors you'd have to send a json object containing the error message.

Agree with Max_power_up...
Just do one addition in case of dummy data , in $msg array along with message also put status and its value as fail or any other related word different from "Complete"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.