你能告诉我这种表格在做什么吗? [英] Can you tell me what this form is doing?

查看:65
本文介绍了你能告诉我这种表格在做什么吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道此表格在做什么.我对Ajax经验不足,而对PHP则只有一点经验.我了解ajax.php是在表单提交后运行的,但我不了解onsubmit部分.

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.

此表单返回错误"Error Parsing JSON"(错误解析JSON),此刻.

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">

推荐答案

onsubmit 只是内联事件,理想情况下,出于可维护性考虑,您可能希望将其抽象为难看.

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 -需要3个参数,第一个是上下文,第二个是成功回调,第三个是错误回调.

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

AlertSet.addJSON(resp).show(); -将resp传递给AlertSet.addJSON方法,然后使用show()方法链接显示警报.

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

以下是PHP找出要通过 tabset_module_name.getTab()方法的内容的方法,或者如果不是 $ verb =='add'的情况,它将调用 .close().

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(); ,它正在调用show方法.

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();
})

长话短说,由于 resp 不是JSON,因此发生了错误,请检查服务器响应的内容,最有可能是HTML

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

这篇关于你能告诉我这种表格在做什么吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆