2013-10-28 8 views
0

"100 MYR"이하의 값을 다른 국가의 통화로 변환 중입니다. 변환기가 JQuery (Google API)를 사용하고 있습니다. 아래의 다른 페이지에서 레이블 (lblAmountPaid)에 값 (변환 된 통화)을 전달하고 싶습니다. 세션 및 쿠키 메서드를 사용했지만 작동하지 못했습니다. 빈 문자열이 반환됩니다. 도와주세요, 고마워요.JQuery에서 ASP.NET으로 값을 가져 오기

enter image description here

ccGOOG.js 아래

$(document).ready(function() { 
$('#submit').click(function() { 
    var errormsg = ""; 
    var amount = $('#txtAmount').val(); 
    var from = $('#drpFrom').val(); 
    var to = $('#drpTo').val(); 
    $.ajax({ type: "POST", 
     url: "WebService.asmx/ConvertGOOG", 
     data: "{amount:" + amount + ",fromCurrency:'" + from + "',toCurrency:'" + to + "'}", 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     beforeSend: function() { 
      $('#results').html("Converting..."); 
     }, 
     success: function (data) { 
      $('#results').html(amount + ' ' + from + '=' + data.d.toFixed(2) + ' ' + to); 
     }, 

     error: function (jqXHR, exception) { 
      if (jqXHR.status === 0) { 
       errormsg = 'Not connect.\n Verify Network.'; ; 
      } else if (jqXHR.status == 404) { 
       errormsg = 'Requested page not found. [404]'; ; 
      } else if (jqXHR.status == 500) { 
       errormsg = 'Internal Server Error [500].'; ; 
      } else if (exception === 'parsererror') { 
       errormsg = 'Requested JSON parse failed.'; ; 
      } else if (exception === 'timeout') { 
       errormsg = 'Time out error.'; ; 
      } else if (exception === 'abort') { 
       errormsg = 'Ajax request aborted.'; ; 
      } else { 
       errormsg = 'Uncaught Error.'; 
      } 
      $('#results').html(errormsg); 
      $('<a href="#" >Click here for more details</a>').click(function() { 
       alert(jqXHR.responseText); 
      }).appendTo('#results'); 
     } 
    }); 
}); 
}); 

다른 페이지입니다 : 나는 당신에 ASP.NET AJAX 페이지 메소드를 호출하는 것이 좋습니다 것입니다

enter image description here

답변

0

당신의 success.ajax() 메서드 콜백, 같은 thi S : 당신이 그것을 구글 API 호출의 결과를 전달 jQuery를 .ajax() 방법의 success 콜백에서 이것을 호출 할 필요가

[WebMethod(EnableSession = true)] 
public static void SetAmountInSession(int amount) 
{ 
    HttpContext.Current.Session["amount"] = amount; 
} 

다음 :

첫째, 여기에 사용할 수 Session와 페이지 방법 이 같은 :

success: function (data) { 
    $('#results').html(amount + ' ' + from + '=' + data.d.toFixed(2) + ' ' + to); 
    var args = { 
     amount: data.d.toFixed(2) 
    }; 
    $.ajax({ 
     type: "POST", 
     url: "YourPage.aspx/SetSession", 
     data: JSON.stringify(args), 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     success: function() { 
      alert('Success.'); 
     }, 
     error: function() { 
      alert("Fail"); 
     } 
    }); 
}, 

마지막으로, "기타"페이지에서, 당신은 다음과 같이 Session의 값을 잡을 수 있습니다

// Check if value exists before we try to use it 
if(Session["amount"] != null) 
{ 
    lblTotalAmount.Text = Session["amount"].ToString(); 
} 
+0

답장을 보내 주셔서 감사합니다. 나는 모두를 따라 갔다. 변환 버튼을 클릭하면 "실패"를 나타내는 메시지 상자가 표시되고 다른 페이지에는 아무런 값도 표시되지 않는다. 나는 왜 그런지 이해하지 못한다. – Roshan

관련 문제