How to user preSubmit function?
How to user preSubmit function?
YudsTable
Posts: 6Questions: 3Answers: 0
I have matter with the preSubmit what can I do with it, I wanna to set the data after deal for submit. such as
data:{
'id':id,
'name',name
}
but it doesn't work, what should I do?(It's my graduate design,please help me)
Thank you very much!
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I'm afraid I don't understand your question. Can you link to a page showing the issue and show your full code.
Allan
ok, I means do you have an example of the preSubmit function or which way can I use to modify the data submit to serverside where the default data like
action=create&data[0][id]=11&data[0][name]=aa
but what I want isid=1&name=aa
Thank you, Allan
I believed the reason you want to do this because you don't use PHP or .NET libraries accompany with datatables?
I suggest to use the library accompany with datatables or transform the ajax request to POST and use JSON.stringify to send the request as JSON string then on the server side decode json string to form an associative array and create a parser from there.
I hope you get what I mean
On the server side
$inputJSON = file_get_contents('php://input');
$input= json_decode( $inputJSON, TRUE ); //convert JSON into array
print_r($input); //walk through the decoded json string and create parser from there. I walk down this path as well to easily parse the data sent by datatables to your preferred scripting language.
OK Thanks your help I got it for use the JSON data ,and I use Java didn't familiar with php and .net so Iām in trouble.Thanks your example again,
By the way,Can I change the submit success function, the default action looks like just modify in the table, but doesn't through the ajax.reload() to reload the table, does this
ajax: {
type: 'POST',
url: '${pageContext.request.contextPath}/index/add',
data: function( data ) {
return JSON.stringify(data);
},
contentType: 'application/json',
success:function(){
dtable.ajax.reload();
}
work?and must I return the default data format?
I don't really understand your question but from the looks of it this is what you need
please siff through the documentation it was clear an concise promise, one of the strength of datatables is very good documentation.
eh,Now I don't have enough time to read the documentation,and my English is poor(I'm a senior of china,I'm doing my final design).
Above all thank you very much, you are friendly!
Have a good day!
sure thing no worries :), i'm not a native english speaker either hehe
loloski ,
I used your code snippet and create & edit servlets are executed when create & edit button is clicked.
Before the servlet is called, I can see JSON data but inside of servlet, I am getting nullpointer exception.
Any suggestions?
```
ajax: {
...
...