AJAX请求前获取日期的JavaScript [英] Obtain dates with JavaScript before AJAX request

查看:161
本文介绍了AJAX请求前获取日期的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的AJAX请求:

I have this AJAX request:

function request(str){
    <script>      
    var aircraft = $("#div");
        aircraft.load("./file.php?icao="+str, function(){
        });
    }
<script>
<div id="div"><div>

当我执行这个选项。请求为file.php

When I execute this option. Request to the file.php

<script>
    $(function() {
        $("#submit")
            .button()
            .click(function form() {
        });
    });

    function form(){

        var id = document.getElementById('id').value;
                $("div2").text(id);
    }
</script>
<div id="div2"><div>
<tr><td class="forms">ID:</td><td><input maxlength="4" type="text" id="id" name="icao" size="30"/></td></tr>

<tr><td><input id="submit" type="submit" value="Submit"></td></tr>

当我preSS按钮有不是一个结果。变种id的值是不确定的。问题是,在功能要求。因为如果我这样做的情况下直接功能一切工作正常。我认为是与AJAX和Javascript的一个问题后。

When I press the button there isn´t a result. The value of var id is undefined. The problem is in the function request. Because if I do directly without the function all works fine. I think is a problem with the AJAX and the Javascript after.

推荐答案

试试这个:

function form() {
    var id = document.getElementById('id').value;
    $("div2").text(id);
}

$(function() {
    $("#submit").click(function() {
      form();
    });
});

在语法中嵌入一个jQuery事件函数调用是不正确的。如果你想执行一个jQuery函数在另一个函数,你必须做以上,而不是。点击(函数形式(){});

这篇关于AJAX请求前获取日期的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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