Anonymous
Rufen Sie den Webdienst von JQuery Ajax an
Post
by Anonymous » 14 Apr 2025, 17:41
Ich habe versucht, die WebService -Methode mit AJAX in ASP.NET anzurufen.
Dies ist meine Webdienstmethode. < /p>
Code: Select all
[WebMethod]
public String registerWS(String email, String firstname, String lastname, String address, String mobile)
{
String query = "insertcrud_sp";
SqlCommand com = new SqlCommand(query, con);
com.CommandType = CommandType.StoredProcedure;
String res = "";
com.Parameters.AddWithValue("@email", email);
com.Parameters.AddWithValue("@firstname", firstname);
com.Parameters.AddWithValue("@lastname", lastname);
com.Parameters.AddWithValue("@address", address);
com.Parameters.AddWithValue("@mobile", mobile);
con.Open();
if (com.ExecuteNonQuery() > 0)
{
con.Close();
res= "true";
}
else
{
con.Close();
res= "false";
}
return res;
}
< /code>
Dies ist mein jQuery -Code .. < /p>
$(document).on("click","#btnajaxcontrol", function () {
var mail = document.getElementById("txtmail").value;
var fname = document.getElementById("txtfname").value;
var lname = document.getElementById("txtlname").value;
var addr = document.getElementById("txtaddress").value;
var mobile = document.getElementById("txtmobile").value;
if (ValidateEmail(mail) && !(mail == "") && !(fname == "") && !(lname == "") && !(addr == "") && !(mobile == "")) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "CRUDwebserviceJS.asmx/registerWS",
data: { 'email': mail, 'firstname': fname, 'lastname': lname, 'address': addr, 'mobile': mobile },
cache: false,
success: function (data) {
var wsres = data.d;
if (wsres == 'true') {
$('#lblmsg').html('User Successfully Registered...');
}
},
error: function (result) {
alert(result);
$('#lblmsg').html('User Registeration faild...!');
$("#lblmsg").css('background', 'red');
}
});
}
});
Die Webdienstmethode funktioniert alleine ... aber wenn ich den Webdienst von AJAX aufrufe>
1744645280
Anonymous
Ich habe versucht, die WebService -Methode mit AJAX in ASP.NET anzurufen. Dies ist meine Webdienstmethode. < /p> [code][WebMethod] public String registerWS(String email, String firstname, String lastname, String address, String mobile) { String query = "insertcrud_sp"; SqlCommand com = new SqlCommand(query, con); com.CommandType = CommandType.StoredProcedure; String res = ""; com.Parameters.AddWithValue("@email", email); com.Parameters.AddWithValue("@firstname", firstname); com.Parameters.AddWithValue("@lastname", lastname); com.Parameters.AddWithValue("@address", address); com.Parameters.AddWithValue("@mobile", mobile); con.Open(); if (com.ExecuteNonQuery() > 0) { con.Close(); res= "true"; } else { con.Close(); res= "false"; } return res; } < /code> Dies ist mein jQuery -Code .. < /p> $(document).on("click","#btnajaxcontrol", function () { var mail = document.getElementById("txtmail").value; var fname = document.getElementById("txtfname").value; var lname = document.getElementById("txtlname").value; var addr = document.getElementById("txtaddress").value; var mobile = document.getElementById("txtmobile").value; if (ValidateEmail(mail) && !(mail == "") && !(fname == "") && !(lname == "") && !(addr == "") && !(mobile == "")) { $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "CRUDwebserviceJS.asmx/registerWS", data: { 'email': mail, 'firstname': fname, 'lastname': lname, 'address': addr, 'mobile': mobile }, cache: false, success: function (data) { var wsres = data.d; if (wsres == 'true') { $('#lblmsg').html('User Successfully Registered...'); } }, error: function (result) { alert(result); $('#lblmsg').html('User Registeration faild...!'); $("#lblmsg").css('background', 'red'); } }); } }); [/code] Die Webdienstmethode funktioniert alleine ... aber wenn ich den Webdienst von AJAX aufrufe>