0

なぜこれが機能しないのかわかりません。私はajaxを介してデータを渡そうとしています。私はこれを何度も使用しましたが、何らかの理由で機能しません。何も返さない。

ここにjsがあります

$('#contactformbtn').click(function(){
    var fullname = $('#fullname').val();
    var youremail = $('#youremail').val();
    var subject = $('#subject').val();
    var yourmessage = $('#yourmessage').val();

    var datastring = 'fullname=' + fullname + '&youremail=' + youremail + '&subject=' + subject + '&yourmessage=' + yourmessage;

    $.ajax({
        type: "POST",
        url: "ajax-contact.php",
        data: datastring,
        success: function(status){
            alert(status);
        }
    });

    //alert(datastring);
    return false;
});

そして、これはphpです

<?php
require 'core/init.php';

if(isset($_POST)){
    $fullname = $_POST['fullname'];
    $youremail = $_POST['youremail'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];

    echo $fullname;
}
?>

Chromeでコンソールをチェックすると、2つのエラーが発生します

Uncaught TypeError: Cannot read property '1' of null
Uncaught TypeError: Cannot read property '3' of null

私の完全なjsはこれです(エラーが連絡機能ではない場合に備えて)

$(document).ready(function(){

$("#download-btn").bind("click", downloadfile);
$(".download-link").hide();

function downloadfile()
{
    var dl = $("#dl").val();
    var counter = 10;

    var interval = setInterval(function(e) {
        counter--;

        if(counter > 0){
            $("#download-btn").html("Your Download will begin in " + counter + " Seconds");
            $("#download-btn").attr("disabled", "disabled");
        } else {
            window.location.href="http://www.forwardfiles.com/get_file.php?i="+dl;
            $("#download-btn").hide();
            $(".download-status").html("<h3 class='center'>Download is complete</h3>");
            clearInterval(interval);
        }

    }, 1000);
}


$('#contactformbtn').click(function(){
    var fullname = $('#fullname').val();
    var youremail = $('#youremail').val();
    var subject = $('#subject').val();
    var yourmessage = $('#yourmessage').val();

    var datastring = 'fullname=' + fullname + '&youremail=' + youremail + '&subject=' + subject + '&yourmessage=' + yourmessage;

    $.ajax({
        type: "POST",
        url: "ajax-contact.php",
        data: datastring,
        success: function(status){
            alert(status);
        }
    });

    //alert(datastring);
    return false;
});

});
4

3 に答える 3

0

私はそれを機能させました、私が持っていたコードは大丈夫でした。問題は、私がphpバージョン5.3を実行していなかったため、それを更新して動作することでした:D. とにかく助けてくれてありがとう

于 2013-10-29T21:15:50.633 に答える
0

Did you try .serialize?

$('#contactformbtn').click(function(){
$.ajax({
    type: "POST",
    url: "ajax-contact.php",
    data: $("form").serialize(),
    success: function(status){
        alert(status);
    }
});

//alert(datastring);
return false;

});

于 2013-10-29T19:56:33.987 に答える
0

これらの値の場合、HTML コードをチェックインしてください

var fullname = $('#fullname').val();
    var youremail = $('#youremail').val();
    var subject = $('#subject').val();
    var yourmessage = $('#yourmessage').val();

「name」タグだけでなく、ID を定義している

于 2013-10-29T20:07:19.840 に答える