Diferències
Ací es mostren les diferències entre la revisió seleccionada i la versió actual de la pàgina.
| development:jquery:start [14/02/2020 05:12] – creat mate | development:jquery:start [02/03/2020 03:44] (actual) – [ejemplo] mate | ||
|---|---|---|---|
| Línia 28: | Línia 28: | ||
| <input type=" | <input type=" | ||
| </ | </ | ||
| + | |||
| + | == petición AJAX y modificación DOM | ||
| + | * boostrat | ||
| + | * custom-control-input | ||
| + | * toast | ||
| + | * DataTable | ||
| + | <code javascript> | ||
| + | $(document) | ||
| + | .ready(function () { | ||
| + | |||
| + | $('# | ||
| + | |||
| + | $('# | ||
| + | paging: false, | ||
| + | ordering: | ||
| + | select: true | ||
| + | }); | ||
| + | |||
| + | $(' | ||
| + | |||
| + | $(' | ||
| + | window.location = ( $(this).data(" | ||
| + | // | ||
| + | }); | ||
| + | |||
| + | $(" | ||
| + | |||
| + | inputObject = $(this); | ||
| + | clase = ( $(this).val() == " | ||
| + | id = $(this).attr(' | ||
| + | field = $(this).attr(' | ||
| + | isChecked = $(this).is(": | ||
| + | isValue = (isChecked) ? 1 : 0; | ||
| + | datos = { | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | }; | ||
| + | ajaxError = 0; | ||
| + | |||
| + | $('# | ||
| + | |||
| + | jQuery.ajax({ | ||
| + | type: ' | ||
| + | url: '/ | ||
| + | data: datos, | ||
| + | success: | ||
| + | $('# | ||
| + | if ( isChecked ) $(inputObject).parents(' | ||
| + | else $(inputObject).parents(' | ||
| + | $('# | ||
| + | }, | ||
| + | error: function(xhr, | ||
| + | $('# | ||
| + | $('# | ||
| + | $(inputObject).prop(' | ||
| + | }, | ||
| + | dataType:' | ||
| + | }); | ||
| + | |||
| + | }); | ||
| + | }); | ||
| + | </ | ||
| + | <code html> | ||
| + | <script type=" | ||
| + | <script type=" | ||
| + | |||
| + | <div id=" | ||
| + | style=" | ||
| + | <div class=" | ||
| + | <span class=" | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | <div class=" | ||
| + | S' | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | <div id=" | ||
| + | style=" | ||
| + | <div class=" | ||
| + | <span class=" | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | <div class=" | ||
| + | Les dades s'han desat correctament | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | <code php> | ||
| + | <? | ||
| + | session_start(); | ||
| + | // http:// | ||
| + | |||
| + | require_once " | ||
| + | require_once $BASE_PATH." | ||
| + | |||
| + | $codRetronDesc = array( | ||
| + | 0 => ' | ||
| + | 1 => 'error en els paràmetres enviats' | ||
| + | ); | ||
| + | $fieldsPermesos = array(' | ||
| + | |||
| + | $codRetorn = 0; | ||
| + | |||
| + | $id = ( array_key_exists(' | ||
| + | $field = ( array_key_exists(' | ||
| + | $value = ( array_key_exists(' | ||
| + | |||
| + | if ( (array_search($field, | ||
| + | $data = array( | ||
| + | ' | ||
| + | $field => $value | ||
| + | ); | ||
| + | updateControl($data); | ||
| + | $headerRetorn = ' | ||
| + | } else { | ||
| + | $codRetorn = 1; | ||
| + | $headerRetorn = ' | ||
| + | } | ||
| + | |||
| + | $arrRespuesta = array( | ||
| + | " | ||
| + | " | ||
| + | ); | ||
| + | |||
| + | header($headerRetorn); | ||
| + | header(' | ||
| + | echo json_encode($arrRespuesta); | ||
| + | |||
| + | ?> | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||