CodeIgniter Forums
Help in my ajax jqeury to jason parameter passing and stored procedure execution - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Help in my ajax jqeury to jason parameter passing and stored procedure execution (/showthread.php?tid=51185)



Help in my ajax jqeury to jason parameter passing and stored procedure execution - El Forum - 04-24-2012

[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!


Help in my ajax jqeury to jason parameter passing and stored procedure execution - El Forum - 04-25-2012

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