我有一個表單提交給JQuery和Ajax的PHP腳本。 PHP腳本返回一些XML。出於某種原因,Ajax成功函數不會觸發,而錯誤的是。Ajax調用不起作用
任何人都可以看到我要去哪裏錯了嗎?
我jQuery是如下
$('#submit-excuse').submit(function (event) {
event.preventDefault();
ws_url = 'http://jacamo.epiphanydev2.co.uk/content/inc/excuse-submit.php?excuse='+$('input#excuse').val();
$.ajax({
type: 'GET',
url: ws_url,
dataType: "xml",
beforeSend: function() {
$('p#response').text('Sending.');
},
success: function(xmlIn) {
results = xmlIn.getElementsByTagName("ReportID");
},
error: function() {
$('p#response').text('Error.');
}
});
});
而且我的PHP腳本如下:
$excuse = $_GET['excuse'];
$badwords = array (
'one',
'two',
'three',
'four',
'five'
);
if ($excuse == '') {
$error = 'enter something';
} else {
foreach ($badwords as $word) {
$pos = strpos($excuse, $word);
if($pos !== false) {
$passed = false;
}
}
if ($passed !== false) {
$username = 'xxxxx';
$password = 'xxxxx';
$message = $excuse;
$url = 'http://twitter.com/statuses/update.xml';
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
$passed = 'yes';
}
echo "<?xml version='1.0' encoding='UTF-8'?>\n";
echo "\t<result>\n";
echo "\t\t<passed>" . $passed . "</passed>\n";
echo "\t</result>";
}
感謝
什麼錯誤,你得到什麼? – justkt 2010-04-26 13:35:48
'錯誤'功能有三個參數。將它們添加到你的函數,然後輸出它們。請參閱http://api.jquery.com/jQuery.ajax/ – 2010-04-26 13:41:26