2012-11-12 2 views
1

클라이언트 메서드에 GetNextImage 메서드가 있습니다. ASPX 페이지에서 다음 코드가 있습니다.GET 요청을 사용하여 u0027GetNextImage u0027 메서드를 호출하려고했으나 허용되지 않았습니다.

function slideshow() { 
    $.ajax({ 
    type: "GET", 
    contentType: "application/json; charset=utf-8", 
    url: "/RollingScreen.aspx/sample", 
    dataType: "json", 
    data: "{}", 
    success: function (data) { 
     //this changes the image on the web page 
     $('#imgSlideShow').attr("src","~/Images/1.png"); 

     //fires another sleep/image cycle 
     setTimeout(slideshow(), 5000); 
    }, 
    error: function (result) { 
     alert(result.message); 
    } 
    }); 
} 

$(document).ready(function() { 
    //Kicks the slideshow 
    slideshow(); 
}); 

아래와 같은 오류가 표시됩니다.

{"Message":"An attempt was made to call the method \u0027GetNextImage\u0027 using a GET request, which is not allowed.","StackTrace":" at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"} 

제발 도와주세요. 미리 감사드립니다.

+1

"POST"와 같은 오류가 발생하는지 확인하십시오. –

+0

@Kirill : 고마워요 ... 많이 작동했습니다 ... 이제는 setTimeout (slideshow()) 오류가 발생합니다. , 5000); javascript 언급에서 ... 제발 도와주세요 제발 ... – JItendra

+0

'setTimeout (slideshow, 5000)'해야합니다. – Barmar

답변

1

HTTP GET 사용을 나타내는 WebMethod 속성을 사용자에게 추가하십시오.

[WebMethod(EnableSession = true)] 
[System.Web.Script.Services.ScriptMethod(UseHttpGet = true, ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)] 
public static string sample() 
{ 
    //Your Code Which Gets Next Image 
} 

GET 대신 POST를 사용하면 안됩니다.

"POST 요청은 브라우저의 뒤로/앞으로 버튼을 사용하여 올바른 탐색을 망쳐 놓을 수 없으며, 고유 한 작업으로 서버에 데이터를 전송할 때만 사용됩니다. (일반적으로) 리디렉션을 사용하여 서버 응답을받습니다. " - deceze (Is there anything not good using POST instead of GET?)

관련 문제