我有一个ajax形式:
<form id="my_form">
<input type="text" id="field1" />
<input type="submit" value="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)
和js代码:
document.getElementById("my_form").onsubmit = function(e) {
e.preventDefault();
var xhr = new XMLHttpRequest();
//.............. send request to a server
Run Code Online (Sandbox Code Playgroud)
在文档中,它假定表单是普通表单,而不是ajax.我究竟应该如何将隐形reCaptcha整合到我的ajax表单中?例如:
<form id="my_form">
<input type="text" id="field1" />
<div class="g-recaptcha" data-sitekey="12345" data-callback="????></div>
<input type="submit" value="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)
而且,特别是,我应该为"数据回调"处理程序指定什么?同样,在文档中,数据回调提交了一个表单,但是一个普通表单,而我的是ajax.我需要"数据回调"吗?我不应该在我的处理程序中调用recaptcha吗?怎么样?
有"渲染","getResponse"和"执行".我应该使用哪一个?从文档中不清楚.
我在router.ex中有这个:
get "/my_url/my_url2/:token", MySuperController, :my_action
Run Code Online (Sandbox Code Playgroud)
当我这样称呼:
<%= link("something", to: my_super_url(@conn, :my_action, token: "12345")) %>
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
protocol Phoenix.Param not implemented for [token: "12345"]
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
我有个约会。如何通过 Times 对其进行格式化,使其成为以下格式:
Wed, 02 Oct 2002 15:00:00 +0200
Run Code Online (Sandbox Code Playgroud)
或者
Wed, 02 Oct 2002 15:00:00 GMT
Run Code Online (Sandbox Code Playgroud)
或者
Wed, 02 Oct 2002 15:00:00 EST
Run Code Online (Sandbox Code Playgroud)
我试过这个:
Timex.format!(my_date, "%D, %d %M %Y %H:%i:%s T", :strftime))
Run Code Online (Sandbox Code Playgroud)
但它抛出了一个异常:
%Timex.Format.FormatError{message: {:format, "Expected end of input at line 1, column 16"}} (expected a string)
Run Code Online (Sandbox Code Playgroud)
当它被转换成其他更简单的格式时,没有错误。
我的ajax表单有recaptcha,简化代码:
<form>
<input type="email" placeholder="Email" required="true" />
<input type="submit" value="Create account" />
<div class="g-recaptcha" data-sitekey="12345" data-size="invisible"></div>
</form>
Run Code Online (Sandbox Code Playgroud)
出于某种原因,它将reCaptcha呈现在页脚右下角的某个位置.为什么这样以及如何解决?
我有一个列表或数组。如何根据某些条件将其分解为 2 个或 N 个子列表?我在文档中没有找到任何与此相关的内容。
我有自己的插头模块:
defmodule Module1 do
def init(opts) do
opts
end
def call(conn, _opts) do
# if some_condition1
# something
end
# other stuff
end
Run Code Online (Sandbox Code Playgroud)
在router.ex中
pipeline :pipeline1 do
plug(Module1)
end
scope "/scope", MyApp, as: :scope1 do
pipe_through([:browser, :pipeline1])
# .......
Run Code Online (Sandbox Code Playgroud)
现在我想使用相同的模块Module1创建第二个管道和范围:
pipeline :pipeline2 do
plug(Module1)
end
scope "/scope2", MyApp, as: :scope2 do
pipe_through([:browser, :pipeline2])
# .......
Run Code Online (Sandbox Code Playgroud)
但是,如果我要创建第二个模块,那么区别仅在于:
def call(conn, _opts) do
# if some_condition1 and some_condition2
# something
end
Run Code Online (Sandbox Code Playgroud)
也就是说,我只添加了"some_condition2",其他一切都保持不变.
现在,我该怎么做?我是否必须创建与Module1完全相同的模块Module2并轻轻地更改"call"?它会导致代码重复.