== 인자들을 .cs에서 class로 받는 방식 ==
// .aspx
var data = new Object();
data.MRNO = $("#<%=hdnMRNO.ClientID%>").val()
var json_data = JSON.stringify({ data: data });
$.ajax({
type: "POST",
url: "MATS2020.aspx/FillData_ib2",
data: json_data,
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
beforeSend: function () {
ib2.Reset();
LoadPage_ib2();
},
success: function (result) {
$("#<%=hdnREVISION_COUNT.ClientID%>").val(result.d[1]);
Load_REVADD_ib2();
ib2.LoadSearchData(result.d[0], false);
},
failure: function (response) {
alert(response.d);
}
});
// .cs
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] FillData_ib2(GetListParm data)
{
JsonMaker jm = new JsonMaker();
String[] rtnStr = new String[2];
try
{
DBLib.DacLibrary _dacLib = new DBLib.DacLibrary();
DataSet ib2_ds = _dacLib.DsReturnS(300, false
, "WSP_MATS2020_R3"
, ProjectCode
, "MR"
, data.MRNO
);
rtnStr[0] = string.Empty;
rtnStr[0] = jm.getSearchJSON(ib2_ds.Tables[0]);
rtnStr[1] = ib2_ds.Tables[1].Rows[0]["REV_COUNT"].ToString();
}
catch (Exception ex)
{
jm.addJSON("message", ex.Message);
rtnStr[0] = jm.getSaveJSON(-1);
}
finally
{
GC.Collect();
}
return rtnStr;
}
public class GetListParm
{
public string MRNO { get; set; }
}
== Header를 이용한 호출 방식 ==
// .aspx
var actionUrl = "MATS2031.aspx";
actionUrl += "?SHEET_FUNCTION=REVDELETE_ib2";
actionUrl += "&MRKEY=" + $("#<%=hdnMRKEY.ClientID%>").val();
actionUrl += "&REVISION=" + revision
$.ajax({
type: "POST"
, async: true
, dataType: "json"
, url: actionUrl
, data: ""
, beforeSend: function (req) {
req.setRequestHeader("IBUserAgent", "IBSHEET");
}
, success: function (rtnJSON) {
if (rtnJSON["Result"]["Code"] != 10) {
alert(rtnJSON["message"]);
return;
}
else {
// 화면 reload
reload();
}
}
, error: function (data, status, err) {
alert(data.responseText);
}
, complete: function (jqXHR, textStatus) {
doAction("SEARCH_ib2");
$("#<%=hdnREVISION_CHECK.ClientID%>").val("");
}
});
// .cs
protected void Page_Load(object sender, EventArgs e)
{
// IB Sheet
string agent = Convert.ToString(Request.Headers.Get("IBUserAgent"));
if (agent == "IBSHEET")
{
string res = "";
string method = Convert.ToString(Request["SHEET_FUNCTION"]);
switch (method)
{
case "SAVE_ib2":
res = this.Save_ib2(this.Request.Params);
break;
case "DELETE_ib2":
res = this.Delete_ib2(this.Request.Params);
break;
case "REVDELETE_ib2":
res = this.DeleteRev_ib2(this.Request.Params);
break;
}
this.Response.Write(res);
this.Response.End();
}
else
{
if (!IsPostBack)
{
ProjectCode = ReturnCookie("ProjectCode");
}
}
}
private string Delete_ib2(System.Collections.Specialized.NameValueCollection parameters)
{
JsonMaker jm = new JsonMaker();
int code = 10;
try
{
BeginTransactionS();
string strMRKEY = Convert.ToString(Request["MRKEY"]);
String[] arrStatus = parameters.GetValues("sStatus");
String[] arrACTION_YN = parameters.GetValues("ACTION_YN");
String[] arrMTRL_CD = parameters.GetValues("MTRL_CD");
for (int i = 0; i < arrStatus.Length; i++)
{
string _strACTION_YN = arrACTION_YN[i];
string _strMTRL_CD = arrMTRL_CD[i];
if (_strACTION_YN.Equals("1"))
{
ExecuteNonQueryS("WSP_MATS2031_D1"
, ReturnCookie("ProjectCode")
, strMRKEY
, _strMTRL_CD
);
}
}
jm.addJSON("message", "Successfully deleted!");
CommitTransactionS();
}
catch (Exception err)
{
RollbackTransactionS();
jm.addJSON("message", err.Message);
}
return jm.getSaveJSON(code);
}
'IT > javascript' 카테고리의 다른 글
자바스크립트 반올림, 올림, 버림 (0) | 2018.02.13 |
---|---|
txt(json 방식) 파일을 읽어서 ajax로 db 저장 (0) | 2015.12.23 |
Ajax 사용 (Json) (0) | 2015.07.15 |
.net 자바스크립트 radiobutton Checked (0) | 2015.07.10 |
로딩 화면 (0) | 2015.06.11 |