getjson请求失败,当我在我的远程主机中运行时没有问题,但是当我在localhost中运行时,请求失败,出了什么问题?我收到了这个错误:
SyntaxError:意外的令牌<在位置0的JSON中
客户端
$(document).ready(function() {
var getdetails = function(id) {
return $.getJSON("20.php", {
id: "1"
});
} //END FUNCTION getdetails
var searchData = function(user) {
getdetails(user)
.done(function(response) {
if (response.success) {
$.each(response.data.users, function(key, value) {
$.each(value, function(userkey, uservalue) {});
});
} else {
alert("Fail");
}
})
.fail(function(jqXHR, textStatus, errorThrown) {
alert(errorThrown);
});
}; //END FUNCTION searchData
searchData("1");
var socket = io();
socket.emit('room', prompt('suscribe to channel...'));
});
SERVER
var app = require('express')();
var express = require('express');
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.use(express.static('./public'));
var users = [];
var nicks = new Array();
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html');
});
io.sockets.on('connection', function(socket) {
socket.on('room', function(room) {
socket.join(room);
});
});
http.listen(3000, function() {
console.log('listening on *:3000');
});