Server answer with javascript in inline editing mode?

Server answer with javascript in inline editing mode?

edmedm Posts: 19Questions: 6Answers: 0

Hello,

is it possible, to answer an inline editing ajax request with javascript code (without the error "Reason: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data")?

Perhaps something like this:

<script type="text/javascript">
$("div#table_jobsopen_wrapper .buttonOpenJobsAssign").notify("Daten erfolgreich
 gespeichert", "success");
table_jobsassigned_1.row ("#jobgroup-1_jobId-4").remove ().draw (false);
table_jobsassigned_2.row.add ($("<tr id=\"jobgroup-2_jobId-4\">
<td class=\"pan\">PAN-221037<\/td>
<td class=\"jobNo\">156343<\/td>
<td class=\"customerName\">Testkunde 2<\/td>
...
<td class=\"avNote editable\">-<\/td>
<td class=\"jobgroupName editable\">Linie 2<\/td><\/tr>")[0]).draw (false);
</script>

It unexpectedly works :-), but shows the error message above :(.

Answers

  • PaulusPaulus Posts: 69Questions: 17Answers: 5

    The ajax option allows you to pass in a function, you can then decide whether to make a server call or local call.

    See the last section of https://editor.datatables.net/reference/option/ajax

  • edmedm Posts: 19Questions: 6Answers: 0

    My config:

        editor_jobsassigned_2 = new $.fn.dataTable.Editor ({
            ajax: function (method, url, data, success, error) {
                $.ajax ({
                    type: "POST",
                    url:  "ajax.php",
                    data: data,
                    dataType: "json",
                    success: function (json) {
                        success (json);
                    },
                    error: function (xhr, error, thrown) {
                        error (xhr, error, thrown);
                    }
                });
            },
            table: "#table_jobsassigned_2",
            ...
    

    This works:
    data: data

    But i am using the following, and that completly omits the sending of the parameter array (data):

    data: {
        "action": "changeJobAssignedValues"
        },
    
    array(
    ['action'] => 'changeJobAssignedValues'
    )
    

    And i got again the Error message from the editor: "Reason: SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data".

    Is there now way to bypass the editor error message?

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    Is there now way to bypass the editor error message?

    Not really - Editor by default expects JSON in reply. Indeed, even in your own Ajax method you are telling it to expect JSON ( dataType: "json" ) and it sounds like the server is not returning with JSON.

    The only way to bypass it would be to generate the JSON that Editor expects on the client-side and pass that into the success callback function.

    But i am using the following, and that completly omits the sending of the parameter array (data):

    Because you aren't submitting the parameters from Editor. You would need to do something like:

    data: $.extend( data, { action: '...' } )
    

    Allan

This discussion has been closed.