所以我的JS:jQuery.ajax不工作
$('#introorderbtn').click(function() {
var display = document.getElementById("display").value;
var skype = document.getElementById("skype").value;
var music = document.getElementById("music").value;
var ideas = document.getElementById("ideas").value;
$.post('php/intro.php',{id:ID,gname:gname,name:Name,email:email,display:display,skype:skype,music:music,ideas:ideas}, function(data) {
});
jQuery.ajax({
url: 'php/file.php',
type: 'post',
data: {id:ID,gname:gname,name:Name,email:email,display:display,skype:skype,music:music,ideas:ideas},
success: function(data){
$('#results').html(data);
$('#display').val = "";
$('#skype').val = "";
$('#music').val = "";
$('#ideas').val = "";
}
});
});
而我的HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="display = none" id="gal">
<h1>Order a free Introduction</h1>
<p>This is a 2D Intro: about 7 sec. long and choisable with an alpha-transition (so called "Opener").<br>They are in 1920x1080px and 60fps of course!<br> Most clients picked this product, do it like them!<br> When you are not sure about my art, take a look into the Gallery.</p>
<form>
<h1>Gimme some Data:</h1>
<input id="display" type="text" placeholder="Name Displayed in the Intro">
<input id="skype" type="text" placeholder="Your Skype ID">
<input id="music" type="url" placeholder="Music (No Dubstep Trap stuff pls)">
<textarea id="ideas" placeholder="Your Ideas: "></textarea>
<input type="submit" id="introorderbtn">
</form>
<div id="results"></div>
這裏我的PHP
<?php
$id = $_POST['id'];
$gname = $_POST['gname'];
$name = $_POST['name'];
$email = $_POST['email'];
$display = $_POST['display'];
$skype = $_POST['skype'];
$music = $_POST['music'];
$ideas = $_POST['ideas'];
echo("Test");
---msql connection that works 100%---
?>
PHP的獨立工作的W/O問題,但是當我試圖從表單發佈數據,並從其他腳本發佈一些更多的字符串。 成功功能正在工作,但沒有顯示結果。
控制檯上是否有錯誤?如果服務器實際響應,您是否檢查網絡選項卡?你在'success'中添加了一個斷點來檢查'data'的值是什麼? – Joseph
發佈jsbin或jsfiddle總是有幫助的。 – user961954
$('introorderbtn')不會返回任何東西。因此,您設置的行爲永遠不會被觸發。您需要將其更改爲: $('#introorderbtn') – Christoph