Welcome Guest, Not a member yet? Register   Sign In
Help in my ajax jqeury to jason parameter passing and stored procedure execution
#1

[eluser]Unknown[/eluser]
I have a problem in executing my stored procedure using ajax jquery to webservices.

Here is my code.


function generateProductCode() {

var Qty = $("#txtQTY").val();
var centerid = $("#txtCenterID").val();
var accttype = $("#ddlAccntType").val();

if (isCenterDownline = 1) {
var jsonData = JSON.stringify({ qty: Qty, centerId: centerid, accountType: accttype });
}
else {
var jsonData = JSON.stringify({ qty: Qty, centerId: null, accountType: accttype });
}

$.ajax({

type: "POST",
url: "webservices/insertCode.asmx/insertProductCode",
data: jsonData,
contentType: "application/json; charset=utf-8",
//async: false,
dataType: "json",
success: function (mydata) {
alert("Registration Code Generation Successfull!");
},
error: function () {
alert("Failed to generate registration code");
}

});
}

insertCode.asmx:

public void insertProductCode(int qty, string centerId, string accountType)
{
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConnectionString"].ConnectionString))
{
cn.Open();

using (SqlCommand cmd = new SqlCommand("sp_insert_reg_code", cn))
{
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add("@qty", SqlDbType.Int).Value = qty;
cmd.Parameters.Add("@accntStatus", SqlDbType.NVarChar).Value = accountType;
cmd.Parameters.Add("@center_id", SqlDbType.NVarChar).Value = centerId;

cmd.ExecuteNonQuery();
}

}
}

I checked the jsonData variable. It seems to be that the values needed are there. I just don't know why I always end up in my error function. When I tried to put some breakpoint in my insertCode.asmx, still it goes straight to my error function. Does it mean that I'm not able to call my insertCode.asmx? or there's just something wrong with my code. HELP PLEASE!


Messages In This Thread
Help in my ajax jqeury to jason parameter passing and stored procedure execution - by El Forum - 04-24-2012, 01:49 AM



Theme © iAndrew 2016 - Forum software by © MyBB