使用$ .ajax GET不提交请求

时间:2014-07-25 16:30:57

标签: php jquery html ajax fancybox

我遇到了使此代码正常运行的问题。当用户点击“电子邮件页面”链接时,它会在带有地址输入和提交按钮的fancybox中打开。当我单击提交按钮时,没有任何反应。如果我将输入更改为输入,则提交功能有效,但不会发送电子邮件。表单应该在点击后提交,但我不确定代码有什么问题。

的header.php:

$(".emailPage").append('<a class="fancyEmail" href="#emailPage">Email Page</a>');
    $(".fancyEmail").fancybox({'overlayOpacity': 0.9,'hideOnContentClick': false,'frameWidth':300,'frameHeight':100,'onComplete':function(){
$('#emailPage > #send').click(function(){
    $.ajax({
       type: "GET",
       url: "<?php bloginfo('template_url'); ?>/emailPage.php",
       data: "page=<?php bloginfo('url'); ?>/" + $(this).parent().find('#page').val() + "&email=" + $(this).parent().find('#email').val(),
       success: function(msg){
         alert( msg );
            $('#fancy_close').trigger('click');
       }
     });

page.php文件:

<div class="emailPage"></div>
  <div style="display:none" id="fancyBoxHidden">
  <div style="display:visible" id="emailPage">
    <h1 style="font-family:Georgia;color:#98012e;font-size:24px;font-style:italic;;padding:0 0 10px;">Email this page</h1>
    <form id="emailForm">
    <input type="text" id="email" style="display:block;width:192px;" value="Email address" onfocus="this.value=''" />
    <input type="hidden" id="page" value="<?php echo $postID ?>" />
        <img id="send" style="cursor:pointer;float:right;padding-top:10px;" src="<?php bloginfo('template_url'); ?>/images/btn_send.png" alt="Send"/>
    </form>
  </div>
  </div>
  <div class="cleared"></div>

emailPage.php:

<?php

ini_set("sendmail_from", 'info@vasari-lifts.com');
$message = "A friend has requested that you take a look at this site.<br/> <a href=" . $_REQUEST['page'] . "'>Vasari</a> - by Autoquip";
$to = $_REQUEST['email'];
$subject = "View this page from Vasari-lifts.com";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: info@vasari-lifts.com";
$mail = mail($to, $subject, $message, $headers);
if($mail){
    echo  "This page has been sent to: " . $_REQUEST['email'];
}else{
    echo 'error';   
}

&GT;

谢谢!任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:0)

我不确定为什么你需要从div id = #emailPage遍历#send图像 如果您没有在页面上定义任何#send重复ID,这就足够了。 请在这里查看JSBin演示:

http://jsbin.com/yiwovuve/1/edit?html,js,console,output

答案 1 :(得分:0)

尝试进行此更改:您可以使用图片的ID来处理点击事件,而不是此$('#emailPage > #send').click(function(){$('#send').click(function(){

$('#send').click(function(){
    var parameters = {
      page: "<?php echo bloginfo('url'); ?>" + $(this).parent().find('#page').val(),
      email: $(this).parent().find('#email').val()
    };

    $.ajax({
       type: "GET",
       url: "<?php bloginfo('template_url'); ?>/emailPage.php",
       data: parameters,
       success: function(msg){
         alert( msg );
            $('#fancy_close').trigger('click');
       }
     });
});