Javascript 提交表单时的AJAX请求

Javascript 提交表单时的AJAX请求,javascript,jquery,Javascript,Jquery,我在表格中添加了一个我想跟踪的特殊id。如果该id在表单中可用,则应初始化AJAX请求 表格 {!! Form::open(['data-remote', 'action' => 'IncidentsController@store', 'id'=>'incidentEntryForm']) !!} <div class="form-group"> {!! Form::label('city', 'Name:') !

我在表格中添加了一个我想跟踪的特殊id。如果该id在表单中可用,则应初始化AJAX请求

表格

        {!! Form::open(['data-remote', 'action' => 'IncidentsController@store', 'id'=>'incidentEntryForm']) !!}
        <div class="form-group">
            {!! Form::label('city', 'Name:') !!}
            {!! Form::text('city', null, ['class' => 'form-control']) !!}
        </div>
(...)
$.publish
也是我附带的PubSub功能的一个简短脚本

PubSub

(function($) {
    console.log('PubSub OK');
    var o = $({});

    $.subscribe = function() {
        o.on.apply(o, arguments);
    };

    $.unsubscribe = function() {
        o.off.apply(o, arguments);
    };

    $.publish = function() {
        o.trigger.apply(o, arguments);
    };
}(jQuery));
但当我按下submit按钮时,助手脚本的最后一行似乎没有反应。从未调用函数submitAjaxRequest

脚本包含在我的头部部分。为了检查是否加载了它,我在开头包括了console.log。我看到了输出。我想它正在运行。但它不会对表单中的提交媒体做出反应

更新1 当我尝试调用
submitAjaxRequest()
时,我得到一个错误:
uncaughttypeerror:无法读取未定义的属性“preventDefault”

更新2 生成的表单代码如下所示:

<form method="POST" action="http://dev.server.com/incidents" accept-charset="UTF-8" data-remote="data-remote" id="incidentEntryForm"><input name="_token" type="hidden" value="<TOKEN>">
        <div class="form-group">
            <label for="city">Notrufort:</label>
            <input class="form-control" name="city" type="text" id="city">
        </div>

        <!-- Latitude Form Input -->
        <div class="form-group">
            <label for="street">Stra&szlig;e:</label>
            <input class="form-control" name="street" type="text" id="street">
        </div>

        <!-- Notruftyp Form Input -->
        <div class="form-group">
            <label for="type">Notruftyp:</label>
            <select class="form-control" id="type" name="type"><option value="1">CPR</option></select>
        </div>

        <!-- Notruf erfassen Form Input -->
        <div class="form-group">
            <input class="btn btn-primary form-control" type="submit" value="Notruf erfassen">
        </div>

        </form>

但当我点击控制台中的提交按钮时,没有任何反应。我在页面上其他地方的另一个脚本中使用了这个函数。它是否仍然应该对发布做出反应?

您是否尝试过像
submitAjaxRequest()
刚刚尝试过那样调用它。现在我得到了以下错误
uncaughttypeerror:无法读取未定义的属性'preventDefault'
您可以发布生成的HTML吗?可能是闭包中的事件e为空吗?您的代码工作正常:
<form method="POST" action="http://dev.server.com/incidents" accept-charset="UTF-8" data-remote="data-remote" id="incidentEntryForm"><input name="_token" type="hidden" value="<TOKEN>">
        <div class="form-group">
            <label for="city">Notrufort:</label>
            <input class="form-control" name="city" type="text" id="city">
        </div>

        <!-- Latitude Form Input -->
        <div class="form-group">
            <label for="street">Stra&szlig;e:</label>
            <input class="form-control" name="street" type="text" id="street">
        </div>

        <!-- Notruftyp Form Input -->
        <div class="form-group">
            <label for="type">Notruftyp:</label>
            <select class="form-control" id="type" name="type"><option value="1">CPR</option></select>
        </div>

        <!-- Notruf erfassen Form Input -->
        <div class="form-group">
            <input class="btn btn-primary form-control" type="submit" value="Notruf erfassen">
        </div>

        </form>
function reverseGeoCode() {
    $.subscribe('form.submitted', function() {
        console.log("OK");
    })
}