[問題] 關於XMLHttpRequest 和 PHP
用如下的程式碼
我將他的目標網頁從test.html 改成我自己寫的 test.php
<span
style="cursor: pointer; text-decoration: underline"
onclick="makeRequest('test.php')">
Make a request
</span>
test.php 則在資料庫中新增一筆資料 以及 一行 OK 的 echo
我直接連結那個php可以成功新增沒有問題
可是用XMLHttpRequest卻沒有成功(應該說是在IE沒有成功 可是firefox有)
在IE中有把OK alert出來但是沒有在資料庫新增
可是firefox有新增資料卻沒有alert出來
不知道是為什麼
http://wiki.moztw.org/index.php/AJAX_%E4%B8%8A%E6%89%8B%E7%AF%87
<script type="text/javascript" language="javascript">
var http_request = false;
function makeRequest(url) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open('GET', url, true);
http_request.send(null);
}
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
alert(http_request.responseText);
} else {
alert('There was a problem with the request.');
}
}
}
</script>
<span
style="cursor: pointer; text-decoration: underline"
onclick="makeRequest('test.html')">
Make a request
</span>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.123.101.247
※ 編輯: mozan 來自: 140.123.101.247 (07/23 14:10)
推
07/23 15:22, , 1F
07/23 15:22, 1F
→
07/23 15:23, , 2F
07/23 15:23, 2F
推
07/23 15:39, , 3F
07/23 15:39, 3F
→
07/23 15:41, , 4F
07/23 15:41, 4F
推
07/23 15:45, , 5F
07/23 15:45, 5F
推
07/23 16:02, , 6F
07/23 16:02, 6F
推
07/23 16:01, , 7F
07/23 16:01, 7F
→
07/23 16:03, , 8F
07/23 16:03, 8F
→
07/23 16:03, , 9F
07/23 16:03, 9F
→
07/23 16:04, , 10F
07/23 16:04, 10F
→
07/23 18:38, , 11F
07/23 18:38, 11F
討論串 (同標題文章)
以下文章回應了本文 (最舊先):
完整討論串 (本文為第 1 之 3 篇):
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章
-1
12