這是我寫的網頁部分<!DOCTYPE html><html lang="" dir="ltr"> <head> <meta charset="utf-8"> <title>測試用</title> <script> function fasongqingqiu(){ var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("newsa").innerHTML=xmlhttp.responseText; } } xmlhttp.open("POST","http://localhost:8080/",true); xmlhttp.send(); } </script> </head> <body> <div id="myDiv"><h2>使用 AJAX 修改該文本內容</h2></div> <button type="button" onclick="fasongqingqiu()">修改內容</button> </body></html>這是我的nodejs服務器部分,名叫server.js(在圖片里)服務器文件和網頁文件是在一個文件夾中的。打開網頁后點擊按鈕無論是前端還是后臺都沒有反應。以及url部分應該怎么寫
1 回答

慕尼黑5688855
TA貢獻1848條經驗 獲得超2個贊
1.嘗試在<system.web> 配置節加上一下代碼
<webServices>
<protocols>
<add name="HttpPost" />
<add name="HttpGet" />
</protocols>
</webServices>
2.在$.Ajax的error里面看看錯誤信息是什么。如果懷疑是服務器端的問題,可以這樣
$.Ajax
({
type:"post"/*or get*/,
url:" 服務url",
data:{},
success:function(){},
dataType:"xml"/*json*/,
error: function(XMLHttpRequest, textStatus, errorThrown)
{
- 1 回答
- 0 關注
- 1326 瀏覽
添加回答
舉報
0/150
提交
取消