[英]Can you tell me what this form is doing?
I don't understand what this form is doing.我不明白这个表格在做什么。 I'm very inexperienced with Ajax and only somewhat experienced with PHP.我对 Ajax 非常缺乏经验,对 PHP 只有些经验。 I understand that the ajax.php is run after the form is submitted but I do not understand the onsubmit portion.我了解 ajax.php 在提交表单后运行,但我不明白 onsubmit 部分。
This form is returning an error "Error Parsing JSON" at the moment.此表单目前返回错误“解析 JSON 时出错”。
<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">
onsubmit
is just inline event, ideally, for maintainability, you might want to abstract it out as its ugly. onsubmit
只是内联事件,理想情况下,为了可维护性,您可能希望将其抽象为丑陋。
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. handleAjaxForm
- 需要 3 个参数,第一个是上下文,第二个是成功回调,第三个是错误回调。
AlertSet.addJSON(resp).show();
- passes resp to AlertSet.addJSON method then chains to show the alert with show() method. - 将响应传递给 AlertSet.addJSON 方法,然后使用 show() 方法链接以显示警报。
the following is PHP working out what to pass the tabset_module_name.getTab()
method or incase not $verb == 'add'
it calls .close()
.以下是 PHP 计算传递tabset_module_name.getTab()
方法的内容,或者如果不是$verb == 'add'
它调用.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.这是调用 show 方法。
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长话短说,发生错误是因为resp
不是 JSON,请检查您的服务器响应的内容,最有可能的是 HTML
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.