2013-08-20 4 views
0

와 $ 아약스에 콜백 매개 변수를 추가하고 코드 같은 것입니다 -내가 JSONP 사용하여 크로스 도메인 호출의 jQuery Ajax 호출을 구현하기 위해 노력하고 JSONP

$.ajax({ 
    async:true, 
    cached:true, 
    url: 'cfcs/TempRepository.cfc?method=getAllCategories' 
     +'&storeID='+ storeId 
     +'&callback=?', 
    type: 'get', 
    data: '', 
    dataType: 'jsonp', 
    success: PopulateCategoryObject, 
    error: function (xhr, status, error) { 
     console.log(xhr + ',' + status + ',' + error); 
    } 
}); 

function PopulateCategoryObject(results) { 
    //populate the categories 
} 

내가 콜백의 사용과 여기 혼란 스러워요. $ .ajax의 success 속성을 제거하고 콜백 대신 PopbackCategoryObject를 사용하면 =? 같은 -

$.ajax({ 
    async:true, 
    cached:true, 
    url: 'cfcs/TempRepository.cfc?method=getAllCategories' 
     +'&storeID='+ storeId 
     +'&callback=PopulateCategoryObject', 
    type: 'get', 
    data: '', 
    dataType: 'jsonp', 
    error: function (xhr, status, error) { 
     console.log(xhr + ',' + status + ',' + error); 
    } 
}); 

는,이 같은 결과를 반환하게 차이 -

PopulateCategoryObject, jQuery172012112959187034678_1376976441013(// data here) 

그리고, 함수 PopulateCategoryObject이 실행되지 않습니다.

여기서 콜백 함수를 설정하는 방법을 알 수 없습니까? 왜 "jQuery172012112959187034678_1376976441013"이 여기에 결과로 추가됩니까?

감사의 말 전진. 당신이 캐시에 아약스 전화를하지 않으려면

+0

왜 성공 속성을 제거해야합니까? – BorisD

+0

url에 "jQuery172012112959187034678_1376976441013"이 추가되고 여기에서 ajax 호출이 캐시되지 않기 때문에 성공보다는 직접 "PopulateCategoryObject"를 호출하려고합니다. 콜백 = PopulateCategoryObject를 유지하면 캐시 된 상태로 유지 될 수 있습니다. 나는 그것에 대해 확실하지 않다. – Ashmah

답변

1

$.ajax({ 
    cached:true, 
    url: 'cfcs/TempRepository.cfc?method=getAllCategories' + '&storeID=' + storeId, 
    jsonpCallback: 'PopulateCategoryObject', 
    dataType: 'jsonp', 
    error: function (xhr, status, error) { 
     console.log(xhr + ',' + status + ',' + error); 
    } 
}); 
+0

안녕하세요, Arun, PopulateCategoryObject (// result)를 반환하지만 함수가 호출되지 않습니다. 설정해야 할 사항이 더 있습니까? – Ashmah

+0

브라우저 콘솔의 다른 오류 –

+0

아니요, 다른 오류가 없습니다. – Ashmah