无法从此javascript代码调用php文件

时间:2015-08-13 22:37:45

标签: jquery

Index.JS

ListViewItem lv = new ListViewItem(textBox2.Text);
listView2.Items.Add(lv);

//im doing somthing wrong here...
var nonintersect = listView1.Except(listView2).Union(listView2.Except(listView1));

//populate listview3 with the unique numbers...
// foreach (item )
// {

// }

的index.php

var toggle = document.getElementById('toggle'),
  wrapper = document.querySelectorAll('.subscribe'),
  submit = document.getElementById('submit'),
  success = document.querySelectorAll('.subscribe__success'),
  content = document.querySelectorAll('.subscribe__wrapper');
var textdata=document.getElementById('textdata').value;

toggle.addEventListener('click', function() {

  this.className += ' subscribe__toggle__hidden';
  wrapper[0].className += ' subscribe-1__active';
});

submit.addEventListener('click', function() {

$.get( "./mailtest.php?textdata=textdata", function( data ) {
  $( ".result" ).html( data ); //data contains everything mailtest.php printed to screen (if any)
  alert( "Load was performed." );
});
  success[0].className += ' subscribe__success--active';
  wrapper[0].className += ' subscribe-1__success';
  content[0].style.display = 'none';
});

mailtest.php

<!DOCTYPE html>
<html >
  <head>
    <meta charset="UTF-8">
    <title>Subscribe Form #1</title>


    <link rel="stylesheet" href="css/reset.css">


        <link rel="stylesheet" href="css/style.css">




  </head>

  <body>
<form method="get">

    <div class="subscribe subscribe-1">
  <a href="#" class="subscribe__toggle" id="toggle">Sign up for the Beta</a>
  <span class="subscribe__success">You're all in set, check your email.</span>
  <div class="subscribe__wrapper">
    <input type="text" id="textdata" name="textdata" />
    <button id="submit">Sign Up</button>
  </div>
</div>
</form>
<a href="http://codepen.io/collection/DpgWyG" class="more-concepts" target="_blank">See more in this collection</a>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        <script src="js/index.js"></script>

  </body>
</html>

javascript文件没有调用php脚本。我尝试了各种各样的东西,但没有任何作用。

这是完整的代码

// Here we get all the information from the fields sent over by the form.
<?php
$email = $_GET['textdata'];


$to = 'myemailid@gmail.com';
$subject = 'the subject';
$message = 'Email: '.$email;
$headers = 'From: noreply@gmail.com' . "\r\n";

mail($to, $subject, $message, $headers); //This method sends the mail.
echo 'success';

?>

我尝试过各种各样的东西,但到目前为止还没有任何工作,请求任何形式的帮助。

如果需要,您可以从Dropbox链接下载整个代码。

1 个答案:

答案 0 :(得分:0)

除了提交内容之外,没有其他任何内容需要更改。我使用的服务器实际上是在给出问题。

我把它上传到其他地方,它就像一个魅力。

感谢大家的帮助。