我想通過jQuery使用AJAX函數將一些數據返回到我的主頁。目前,我正在將表單上的'action ='用於外部PHP文件,以檢查數據是否正在發送。我現在想使用AJAX將這些數據返回到我的主頁上的div。我有這樣的代碼,但目前它沒有返回任何數據:jQuery + AJAX檢索輸入提交類型發送的數據
$("#ticketSearch").click(function(e) {
e.preventDefault();
var eNameData = ("#postcodeSearch").val();
alert('#ticketSearch clicked'); //this alert doesn't even work!
var dataToSend = 'postcodeSearch=' + eNameData;
$.ajax({
url: "index.php",
type: "POST",
data: dataToSend,
cache: false,
success: function(php_output)
{
$("#ticketResults").html(php_output).show();
}
});
});
的形式代碼:
<form name="pcSearchForm" id="pcSearchForm" class="pcSearchForm" method="post" action="postCodeSearch.php"> // the action method needs to be taken out
<input type="text" name="postcodeSearch" id="postcodeSearch" class="postcodeSearch" placeholder="Postcode..." />
<input type="submit" name="ticketSearch" id="ticketSearch" class="ticketSearch" value="Search" />
</form>
任何幫助非常感謝,我想我是在正確的路線,但東西只是不正確! 謝謝。
編輯:新代碼:
$(document).ready(function() {
$("#ticketSearch").click(function(e) {
alert("click");
e.preventDefault();
var eNameData = $("#postcodeSearch").val();
alert('eNameData');
});
var dataToSend = 'postcodeSearch=' + eNameData;
$.ajax({
url: "index.php",
type: "POST",
data: dataToSend,
cache: false,
success: function(php_output)
{
$("#ticketResults").html(php_output);
alert("#ticketResults");
}
});
});
形式:
<input type="text" name="postcodeSearch" id="postcodeSearch" class="postcodeSearch" placeholder="Postcode..." />
<input type="button" name="ticketSearch" id="ticketSearch" class="ticketSearch" value="Search" />
</form>
你可以嘗試調試螢火蟲中的ajax調用 – Sabari 2012-03-02 16:01:39
去螢火蟲的網絡面板。檢查控制檯 – Sabari 2012-03-02 16:52:03
是否有任何錯誤可以嘗試提醒輸出。我懷疑ajax調用是否返回空輸出。他們的任何網址,我可以檢查? – Sabari 2012-03-02 17:19:55