我創(chuàng)建了一個極簡的APINodeJS返回JSON格式的數(shù)據(jù)。但是,每次我嘗試進行Ajax#GET調(diào)用并將API作為URL傳遞時,我將得到一個錯誤,從Chrome判斷,我將得到一個"Unexpected token :"錯誤;中的服務(wù)器代碼NodeJS + 特快:var
http = require( 'http' ),
express = require( 'express' ),
app = express(),
server = http.createServer( app );app.get( '/', function( req, res ) {
console.log( 'req received' );
res.setHeader('Content-Type', 'application/json');
res.end( JSON.stringify({
Name : "Tom",
Description : "Hello it's me!"
}) );});server.listen(3000, function() {
console.log( 'Listening on 3000' );});返回的JSON"/"是:{"Name":"Tom","Description":"Hello it's me!"}.這是我從客戶端js打來的電話:$.ajax({
url: findUrl,
type: 'get',
dataType: 'jsonp',
success: function ( data ) {
self.name( data.Name );
self.description( data.Description );
},
error: function( jqXHR, textStatus, errorThrown ) {
alert(errorThrown);
}});在繪制錯誤時,我得到:"jQuery111108398571682628244_1403193212453 was not called"有人能幫我嗎?我知道這個問題已經(jīng)問過了,但我還沒有找到一個解決方案來解決我的程序。
jQuery.ajax#get之后的意外令牌冒號JSON
一只萌萌小番薯
2019-07-13 16:07:19