Html &引用;“语法错误”;在发出Ajax POST请求时
我试图在nodeJs中使用Ajax发出POST请求。当我运行函数Html &引用;“语法错误”;在发出Ajax POST请求时,html,node.js,ajax,Html,Node.js,Ajax,我试图在nodeJs中使用Ajax发出POST请求。当我运行函数alert(status)时,会弹出parseerror。这个Ajax调用有什么问题 function ajaxmagic() { $.ajax({ url : 'FetchSongs.php', type : 'POST', data : {username: "maxolgin"}, dataType: "json", success : funct
alert(status)
时,会弹出parseerror
。这个Ajax调用有什么问题
function ajaxmagic() {
$.ajax({
url : 'FetchSongs.php',
type : 'POST',
data : {username: "maxolgin"},
dataType: "json",
success : function (result) {
var i;
for (i = 0; i < result.length; i++) {
var table = document.getElementById("myMixTable");
table.style.borderCollapse = "seperate"
var rowCount = table.rows.length;
console.log(table.rows.length)
var row = table.insertRow(0);
var row2 = table.insertRow(1);
var cell1 = row.insertCell(0);
cell1.rowSpan = "2"
cell1.setAttribute("class", "MixImage")
var image = document.createElement("img");
image.style.padding = "0px 0px 0px 0px"
cell1.appendChild(image)
var cell2 = row.insertCell(1);
cell2.style.width = "300px"
var title = document.createElement("td");
title.innerHTML = result[i].songTitle
cell2.appendChild(title);
var artistCell = row2.insertCell(0);
var artistTitle = document.createElement("td");
artistTitle.style.fontSize = "13px"
artistCell.appendChild(artistTitle);
var timestampCell = row.insertCell(2);
timestampCell.rowSpan = "2"
timestampCell.style.horizAlign = "right"
var timestamp = document.createElement("td");
timestamp.style.horizAlign = "right"
timestampCell.appendChild(timestamp);
}
},
error : function (jqxhr, status, exception) {
alert(status);
}
});
}
函数ajaxmagic(){
$.ajax({
url:'FetchSongs.php',
键入:“POST”,
数据:{用户名:“maxolgin”},
数据类型:“json”,
成功:功能(结果){
var i;
对于(i=0;i
无论您使用的是nodejS还是前端react,都应该使用绝对路径,因为我怀疑是否有人在同一主机和端口上运行nodejS和php
FetchSongs.php
应更改为http://hostname:port/FetchSongs.php
检查“网络”选项卡和后端日志,了解请求失败的原因您在node.js中执行此操作?@law非常确定。它是一个.js文件现在它只是说error而不是parseerror