• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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!

#2
[eluser]vitoco[/eluser]
Wrong place to ask ( Codeigniter = PHP , not ASP )...that's even worse that a bad question....


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.