2013-10-17 48 views
-2

我在做什麼錯?下列不upate我的JSON對象:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 

function getJson() { 
    $.getJSON("http://laptop/EstimatorWeb/GetConfig.ashx", function (da) { 
     json = da; 
     //document.getElementById("resDiv").innerText=da; 
    }).success(function() { 
     alert("second success"); 
    }).error(function() { 
     alert("error"); 
    }); 

我可以看到我的Web服務返回的提琴手JSON對象。這只是最後一塊不更新對象。我沒有收到任何成功或錯誤的警報。

+1

將'http:// laptop/EstimatorWeb/GetConfig.ashx'更改爲有效的網址 –

+2

@TamilSelvan:您是否試圖關注該網址? –

+0

'http:// laptop/EstimatorWeb ...'看起來不像一個有效的URL。 –

回答

0

你需要使用.done()和.fail(),.success()和.error()是在V1.8 deprecated fiddle example

$.getJSON("http://laptop/EstimatorWeb/GetConfig.ashx", function(json){ 
     $("#resDiv").text(json); 
    }).done(function(data){ 
     alert('second done' + data.Host); 
    }).fail(function(e){ 
     alert('fail'); 
    }); 

你只需要到JSON轉換字符串

+0

試過這個,仍然沒有得到任何東西... URL是一個.NET的Web服務,並返回一個JSON對象,我使用瀏覽器進行測試。問題僅限於JavaScript中的此功能。不知道什麼是錯,因爲我對JavaScript和jQuery非常陌生。 – ybittu

+0

@ybittu如果您從完成中刪除警報並添加一個而不是$(「#resDiv」)。text(json);你有沒有得到警報? –