어떤 코드를 시도했는지, 또는 실제로 시도한 것이 확실하지 않습니다. 당신은 당신의 클라이언트에 몇 가지 방법으로 데이터를 푸시 할 수 있습니다
Page.ClientScript.RegisterStartupScript(
this.GetType(), @"NameOfFunction", @"alert('Message');");
실제로 뒤에있는 코드에서 자바 스크립트를 호출, 분명히이 방법은 몇 가지 단점이있다. 문제의 메시지가 어디에서 유래 되었는가가 뻔뻔스럽지 않은 것처럼 문제 해결이 항상 명확하지는 않습니다.
둘째로, 모두 강력한 것입니다 $.ajax
. 이 접근 방식을 사용하면 사실상 추상적 인 비트를 생성 할 수 있습니다. 당신은 예를 들면 돌아 오는 값이 될 겁니다 : 우리의 빌더가
// Build our object with a Clean Constructor:
function BuildOrder(Product, Quantity, Price) {
var item = null;
if(Product & Quantity & Price) {
Product: Product,
Quantity: Quantity,
Price: Price
};
}
는, 우리는 우리의 object
을 구축 할 수 있습니다.
var order = new Array();
order.push(BuildOrder(product, quantity, price));
convertedOrder = JSON.stringify(order);
그런 다음 당신은 클라이언트에서 서버로 전달하는 데 기본적으로 거대한
string
인
JSON
값을 가지고있다. 그런 다음
Ajax
을 만듭니다.
$.ajax({
url: '<%= Page.ResolveUrl("~/Services/Credit.aspx") %>',
data: { Order: convertedOrder },
type: 'POST',
success: function (order) {
var result = JSON.parse(order);
$("#<%= txtTax.ClientID %>").val('$' + result[0].Tax).change();
$("#lblTotal").text('$' + result[0].Total);
},
failure: function() {
alert('There was an error in retrieving the total and tax, please continue inputting for it to automatically refresh.');
}
});
}
는 서버에 당신은 단지 직렬화 당신이 그것을 반복 한 후 다시 직렬화 할
JavaScriptSerializer
를 사용합니다.
success
및
failure
이 반환되므로 처리됩니다.