Ajax IndexedDB Delete Current Sucesfull Upload

后端 未结 2 1708
萌比男神i
萌比男神i 2021-01-23 12:01

I posted something similar yesterday but it works but only deleted the last object in the data.

What I want to happen

This ajax upload will be h

2条回答
  •  情歌与酒
    2021-01-23 12:26

    The only solution I found worked with this was to send the Key via ajax to php then delete from that.

    HTML

    var passData = {     
                            .......
                            key: res.key,
                        };
    
    .....
    
       $.ajax({
                           url: "yourscript.php",
                           type: "post",
                           data: {
                               "json": passData 
                           },
    
                           success: function(JsonData) {
    
                               jsonKey = JSON.parse(JsonData);
    
    
                               //Delete item once successfull 
                               var t = db.transaction(["data"], "readwrite");
                               var request = t.objectStore("data").delete(parseInt(jsonKey.key));
                               t.oncomplete = function(event) {
                                console.log('item deleted', jsonKey.key);
                               };
    
    
    
                           }
    

    PHP

        $data = $_POST['json'];
    
    
        $returnKey =  json_encode(
                        array(
                                'key' => $data['key']
                        )
        );
    

提交回复
热议问题