Can you tell me what this form is doing?

若如初见. 提交于 2021-02-11 12:22:27

问题


I don't understand what this form is doing. I'm very inexperienced with Ajax and only somewhat experienced with PHP. I understand that the ajax.php is run after the form is submitted but I do not understand the onsubmit portion.

This form is returning an error "Error Parsing JSON" at the moment.

<form
    action="<?=$module->path?>/ajax.php"
    method="post"
    enctype="multipart/form-data"
    class="tabmin_form"
    onsubmit="return handleAjaxForm(this, function(resp){AlertSet.addJSON(resp).show(); tabset_<?=$module?>.<?=$verb=='add'? 'getTab(\''.$tab.'\').reload(false)' : 'getTab(\''.$tab.$workshop->id.'\').close(false)'?>; tabset_<?=$module?>.getTab('view').show();}, function(resp) {AlertSet.addJSON(resp).show();})"
    autocomplete="off">

回答1:


onsubmit is just inline event, ideally, for maintainability, you might want to abstract it out as its ugly.


Pull it out and format then break down each line.

handleAjaxForm - takes 3 args, first is the context second is the success callback and third is an error callback.

AlertSet.addJSON(resp).show(); - passes resp to AlertSet.addJSON method then chains to show the alert with show() method.

the following is PHP working out what to pass the tabset_module_name.getTab() method or incase not $verb == 'add' it calls .close().

tabset_<?=$module?>.<?=$verb=='add'? 'getTab(\''.$tab.'\').reload(false)' : 'getTab(\''.$tab.$workshop->id.'\').close(false)'?>;

then final line in the success callback:

tabset_<?=$module?>.getTab('view').show(); which is calling the show method.

return handleAjaxForm(this, function(resp){
  //
  AlertSet.addJSON(resp).show(); 

  //
  tabset_<?=$module?>.<?=$verb=='add'? 'getTab(\''.$tab.'\').reload(false)' : 'getTab(\''.$tab.$workshop->id.'\').close(false)'?>; 

  //
  tabset_<?=$module?>.getTab('view').show();
}, function(resp) {
   AlertSet.addJSON(resp).show();
})

Long story short, the error is happening because resp is not JSON, check what your server is responding with, its most likely HTML



来源:https://stackoverflow.com/questions/63250477/can-you-tell-me-what-this-form-is-doing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!