I am attempting to send parameters to my code behind using the WebMethod.
Although I am successfully reaching the end of ajax, the method in my aspx.cs code behind is not being called and I am encountering an error.
Operation failed! Details: '[object Object]'
I am utilizing a masterpage and wonder if that might be causing any issues.
How can I resolve this issue?
I would greatly appreciate any assistance. Thank you!
Javascript:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/json2/0.1/json2.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=imgfasi]").bind("click", function () {
var fasi = {};
fasi.Txseltlc = $("[id*=txseltlc]").val();
fasi.Txrescldisa = $("[id*=txrescldisa]").val();
fasi.Ddlauttlc = $("[id*=ddlauttlc]").val();
$.ajax({
type: "POST",
url: "Default.aspx/Savepnfasi",
data: '{fasi: ' + JSON.stringify(fasi) + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response == "1") {
alert("Success!");
} else {
alert("Operation failed! Details: " + response);
}
}
});
return false;
});
});
</script>
Code Behind :
public class pnfasiweb
{
public string Txseltlc { get; set; }
public string Txrescldisa { get; set; }
public string Ddlauttlc { get; set; }
}
[WebMethod]
[ScriptMethod]
public static void Savepnfasi(pnfasiweb fasi)
{
if (!String.IsNullOrEmpty(HttpContext.Current.Request.QueryString["id"]))
{
string ProductID = Mpskmt3.Base64ForUrlDecode(HttpContext.Current.Request.QueryString["id"].ToString());
// SQL Update command
using (OdbcConnection cn =
new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnMySQLlocalhost"].ConnectionString))
{
using (OdbcCommand command =
new OdbcCommand(sql, cn))
{
try
{
command.Connection.Open();
// Set Parameters
command.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
}
finally
{
command.Connection.Close();
}
}
}
}
else
{
// Handle Error
}
}
#Edit01