简体   繁体   中英

Ajax Iframe trigger click submit

Hello fellow StackOverflow. I need a favor on Ajax this time.

This is my Ajax code.

$('#contactForm1').submit(function (e) {
    e.preventDefault();
    var email = $('#email').val();
    var frm = this;
    $.ajax({
        type: 'POST',
        dataType: 'JSON',
        url: 'check.php',
        data: {
            email: email
        },
        success: function (data) {
            if (data.status == 'success') {
                frm.submit();
            } else {
                alert('The e-mail address entered is not valid.');
            }
        }
    });
});

This is the iFrame code :

    <div class="iFrame"><input class="text" id="iframetarget1" type="text" name="email" value="" tabindex="500" onfocus=" if (this.value == '') { this.value = ''; }" onblur="if (this.value == '') { this.value='';} " />
<div class="buttonContainer">
<input name="submit" class="submit" type="submit" value="Submit" tabindex="501" />

So here's what I want the scenario to occur,
1. Pass the information after the Ajax check the email to and submit the form.
2. Submit the same email in the iFrame and submit it.

Thank you in advance !

U can use $(window.frames[0].document) get iframe content, then operate it as normal. Such as:

$(window.frames[0].document).find('#iframetarget1').val(email);
$(window.frames[0].document).find('.submit').trigger('click');

http://fiddle.jshell.net/du5sazay/1/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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