Datatable Editor modal doesn't close after "Create" is pressed.
Datatable Editor modal doesn't close after "Create" is pressed.
I've been researching the issue and it sounded like I had to return the data of the changed rows in a JSON object, which I have done. Except I am getting a 404 when I submit the new row.
error: "Not Found"
message:
"/WEB-INF/jsp/{"data":"the row's json data"}.jsp"
path: "/newscanner"
status: 404
timestamp: "2018-07-25T19:24:44.170+0000"
It appears like it is looking for a jsp to navigate to.. but when I provide it with one of the jsp pages it returns a different error.
Any ideas on what I might be doing wrong?
Thank you!
This question has accepted answers - jump to:
Answers
Sounds like Editor is attempting to submit to
"/WEB-INF/jsp/{"data":"the row's json data"}.jsp"
which isn't available on the server. Were you expecting it to be?What is the URL you are expecting it to submit to?
Can you show me your Editor initialisation code please?
Allan
Of course:
It submits just fine to the database, but the response errors out with what I posted above and the modal for creation just hangs there. I have to refresh the page to reuse the modal to insert more objects.
*Apologies is this is my third comment, my other two didn't seem to come up in the form.
Hi,
I've just altered your account so it will bypass spam filters, which is probably what happended to your other posts - sorry!
You are passing in the
success
function on line 3 for the anon Ajax function, but it still isn't being called anywhere, so Editor can't know that the submission is complete. You need to add something likesuccess( response );
around line 12-13, whereresponse
is the JSON Editor expects in response.Allan
It appears as if the same thing is happening for the 'remove' button option as well. The call is made and is successful, but the modal refuses to close.
I added the success(response) and it still seems to hang.
So adding the success(reponse) to the 'remove' button seems to work now, so thank you for that! But I do still have the issue of the data being used to look up a jsp page and getting an error.
Ah-ha! So after I returned null from the endpoint on my backend, it just tried to find the endpoint's jsp page, which didn't exist. So I made one, just a blank jsp file, and that got rid of the error.. however, I still get an error that I just found out is a "Unexpected end of JSON input"
Full error:
Not sure what to do with this... but hopefully I can figure it out. If anyone has any pointers, please let me know!
Figured that out too. Datatables apparently do not like when you try to tell them that your dataType is json.. so I removed
dataType: "json",
from my ajax call and that resolved the issue.if you created a blank page for data tables to use, then no data is being returned and that will cause an error.
You are now using
success(response);
- what is contained inresponse
? Does it match what Editor expects?Allan
@Bindrid2 That isn't the case as, I had created the blank page that the editor was looking for and it works just fine now. I'm not expecting any data to be returned as I am making a POST call.
@allan response contains the json data of the row that was affected in the database. The row that was updated or inserted.
Can you show me that JSON please? The data for the row should be contained in a
data
array, as the documentation I linked to shows.Allan
Here is what comes back as the response:
But when I have the back-end return that data, the modal refuses to close. When I have the back-end return nothing it closes just fine.
However, when I try to do
(#table).DataTable().ajax.reload()
I get an error about unable to read the length of undefined.Yup - that's not what Editor would expect. Try this:
I just spotted as well that there is a typo in
response
in your sample code above.Allan
That gave me an "Unexpected end of JSON input" error.
I got it to give me a "Unexpected token o of Jason at position 1" I'm not sure which is better to work with...
With the quotes being escaped (`\") it leads me to believe your server script is encapsulating the data in JSON twice before returning it to the web browser.
That error reinforces the double encapsulation.
Kevin
This is what I have currently and I am getting the
Uncaught TypeError: Cannot read property 'length' of undefined
when I go to submit the editThis:
Should be:
That was an error in my code above, sorry.
Allan
Spot on help, @allan
I am having some other difficulties, but I understand what the issue with them is so I will try to resolve them myself first.
Thank you very much for your help!
For the error: DataTables warning: table id=table - Requested unknown parameter 'variable' for row 85, column 0.
Does that refer to the table or the editor, or does it depend on other context?
It is referring to the data returned from the ajax request. The returned data structure doesn't match what Datatables is expecting. The error has a link to troubleshooting steps. Have you tried those?
https://datatables.net/manual/tech-notes/4
Kevin
I figured it out, I needed to provide it with json.data. Just json had the
action: 'create'
property and that was causing an issue.Currently, having issue with reloading the table after submission. I'm getting
"Cannot set property 'data' of null"
when I try to call table.ajax.reload() this one has had me stumped.Turns out I was missing the ajax field within my table definition, however I have an exterior $.ajax() call that creates the table in .done(). If I remove the $.ajax() call, the table doesn't get populated to start.
Got to a point where I have no errors when I make my edit, but table.ajax.reload() does not seem to reload the page.. any pointers?
It appears that I had to clear the table, add the new rows, then redraw the table.
That can be shortened to be:
Allan