I am having trouble with PUT/DELETE URL in ajax calls

I am having trouble with PUT/DELETE URL in ajax calls

ChuckTChuckT Posts: 8Questions: 4Answers: 1

I am having an issue with the URL that is being rendered when I make a call to delete or update a table row. DataTables is adding a query string to the end.

i.e.

apiProtectedPath + "vehicle/undefined?action=remove&data%5B18816011-f2af-4570-b7e…el%5D=&data%5B18816011-f2af-4570-b7ec-b8d0fcce1948%5D%5Bis_available%5D=:1

What I need to have is

apiProtectedPath + "vehicle/" + vehicleIdToUse, 

with nothing in between.
I am using the current version of DataTables and Editor with a Postgres backend.

Below is the snippet of my delete portion of the Editor.

remove: {
                type: 'DELETE',
                dataSrc: "data.vehicles",
                processData: false,
                url: apiPathProtected + "vehicle/" + vehicleIdToUse,
                beforeSend: function (request) {
                    request.setRequestHeader("X-Access-Token", user.token);
                    request.setRequestHeader("Content-Type", "application/json");
                }              
            }

This question has an accepted answers - jump to answer

Answers

  • ChuckTChuckT Posts: 8Questions: 4Answers: 1
    Answer ✓

    I have solved this issue, Thanks

  • allanallan Posts: 63,258Questions: 1Answers: 10,421 Site admin

    Thanks for posting back. Great to hear you have it resolved now.

    Regards,
    Allan

  • ChuckTChuckT Posts: 8Questions: 4Answers: 1

    So here is the code that solved my problem. Using id in the URL string did exactly what I needed.

    remove: {
                    type: 'DELETE',
                    dataSrc: "data.vehicles",
                    processData: false,
                    //add _id_ to the end of the url 
                    url: apiPathProtected + "vehicle/_id_",
                    beforeSend: function (request) {
                        request.setRequestHeader("X-Access-Token", user.token);
                        request.setRequestHeader("Content-Type", "application/json");
                    },
    
This discussion has been closed.