2016-11-14 93 views
0

我對理解mockjax有一些小問題。我有這個mockjax代碼:mockjax響應不起作用

$.mockjax({ 
    url: "get_image.php", 
    responseText:{ 
    hello: 'world' 
    } 
}); 

什麼應該是js代碼來提醒'世界'?也許這個?

$.getJson("url" , function(){ 
    alert(response.hello) 
}); 

但這不行,請幫幫我!

+1

也許反應是不確定的,我覺得應該是'功能(響應)' –

+0

它應該是這樣的 '$ .getJson( 「get_image.php」 功能(響應) { alert(response.hello) });' –

+0

我不知道,但這是偷工不了。 –

回答

0

你忘了在函數中添加參數response

$.getJson("url" , function(response){ 
    alert(response.hello); 
}); 

Read more about getJson()

+0

這是竊取不工作,response.hello操作系統未發現,也許在mockjax代碼中的錯誤,你可以檢查它嗎? 但我認爲這是正確的 –

+0

你可以請更新與'響應'值的問題?它說它在'response'中找不到'hello'元素。 –