简体   繁体   English

从输入字段获取值并使用ajax传递到新页面,而无需提交表单

[英]Get value from input field and pass to new page using ajax without submitting form

I have a form which has an email field: 我有一个包含电子邮件字段的表单:

<input type="email" id="email" name="email"/>

And a verify button: 还有一个验证按钮:

<span style="cursor:pointer">
 <p id="verify">Verify</p>
</span>

When user clicks on this verify , an input field(in verify_ajax.php) is loaded using following script which ask for verification code, 当用户单击此verify时 ,将使用以下要求输入验证代码的脚本来加载输入字段(verify_ajax.php中)

<script>
 $function()
 {
    $('#verify').click(function(){

    $('#getcode').load('verify_ajax') 

    }
 }
</script>

Here, getcode is where the ajax content will be loaded. 在这里, getcode是将加载ajax内容的位置。 Now, i want to pass email to the page verify_ajax (loaded in above function). 现在,我想将电子邮件传递到verify_ajax页面(在上述函数中加载)。 I am new to all this ajax, please help me with this code. 我对所有这些ajax都是陌生的,请帮我提供这段代码。

UPDATE: I passed using ajax like: 更新:我通过使用像这样的ajax:

<script>
 $function()
 {
    $('#verify').click(function(){

    $('#getcode').load('verify_ajax?email='+$('#email').val()) 

    })
 })
</script>

And, there is no error, verification code input is loading. 并且,没有错误,正在加载验证码输入。 But there is no email on verify_ajax, I think i am doing some mistake on that page: verify_ajax.php 但是verify_ajax上没有电子邮件,我认为我在该页面上犯了一些错误: verify_ajax.php

if(isset($_GET['email'])
    echo 'Working'.$_GET['email']

This is showing only Working as output. 这是只显示工作作为输出。

use form serialization and then send it to the page. 使用表单序列化,然后将其发送到页面。

var data = $('#FormId').serializeArray();
$('#getcode').load('verify_ajax',data);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM