问题
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