How to get value from XML response from webmethod in c# - asp.net

"<"?xml version=\"1.0\" encoding=\"utf-8\"?>
"<"string xmlns=\"http://xyz.org/\">
Hello World
"<"/string>
I want to get Hellow World. Then What to do?

If you are using jquery:
$(document).ready(function() {
$("#Result").click(function() {
$.ajax({
type: "POST",
url: "Default.aspx/MyWebMethod",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(msg.d);
}
});

Related

AJAX Post with multiple parameter to Razor Pages

I am trying to do an ajax post request with multiple parameters. The method is called on server side but the parameters returns null. What am I doing wrong here? I've tried with and without JSON.stringify.
.cs file:
public async Task<IActionResult> OnPostGenerate(string fname, string lname)
{
return new JsonResult(fname + lname);
}
AJAX script:
$.ajax({
type: "POST",
url: "Index?handler=Generate",
dataType: "json",
contentType: "application/json; charset=utf-8",
headers: {
RequestVerificationToken:
$('input:hidden[name="__RequestVerificationToken"]').val()
},
data: JSON.stringify({
fname: "testFirstname",
lname: "testLastname"
}),
success: function (data) {
alert(data);
}
});
Try to change
data: JSON.stringify({
fname: "testFirstname",
lname: "testLastname"
}),
to
data: {
"fname": "testFirstname",
"lname": "testLastname"
},
and remove
contentType: "application/json; charset=utf-8",

Is there any way for Self-signed certificate for cordova?

We have an API which uses SSL but the certificate is not signed for now. Is there way to bypass the self-signed certificate?
$.ajax({
url: "https://xxxxx:50000/b1s/v1/Login",
xhrFields: {
withCredentials: true
},
data: jData,
type: "POST",
dataType: "json",
crossDomain: true,
error: function (xhr, status, error) {
alert(xhr);
},
success: function (json) {
alert("Success!");
}
});
I've created a simple asp.net MVC with that jQuery, it can login successfully.

Call Web API on Cross Domain

I have a WebAPI and I need AJAX call to access this
but on the cross domain
Here is my code :
$.ajax({
type: "POST",
url: '/api/myapiname/apiactionname',
contentType: "application/json",
data: {
name: "Abhishek",
email: "abhi#abhi.com",
password: "******"
},
crossDomain:true,
success: function(data) { console.log(data); },
error: function(data) {console.log(data); },
dataType: 'json',
beforeSend: function (xhr) {
xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
},
});
Have you enabled CORS within your API? Follow the link, http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api

internal server error on $.ajax call in asp.net

$.ajax({
type: "POST",
url: "AppForm.aspx/ValidateIFSC",
data: "{'BannkIFSC':'" + $("#<%=ui_txtIFSCCode.ClientID %>").val() + "'}",
dataType: "json",
contentType: "application/json; charset=utf-8",
async: true,
cache: false,
success: function (result) {
boo = result.d
}
});
It's working fine in local, but it is not working on the server.
var xx = $("#<%=ui_txtIFSCCode.ClientID %>").val();
$.ajax({
type: "POST",
url: "AppForm.aspx/ValidateIFSC",
// data: "{'BannkIFSC':'" + JSON.stringify(xx) + "'}",
data:'{"BannkIFSC":"'+ JSON.stringify(xx)+'"}',
dataType: "json",
contentType: "application/json; charset=utf-8",
async: true,
cache: false,
success: function (result) { boo = result.d }

Sending data to controller by Ajax

Usually we send data to controller by ajax like following::
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/Controller/MyAction",
data: "{'Name':'" + id + "','Class':'" + cls + "'}",
dataType: "json",
See I have to members to send to controller by two different parameters.
I want to send it as a list.
but What I want is to send a list to the controller in just one parameter. Is it possible but how can I achieve that?
JSON.stringify is the key here.
Here is the code:
var myList = { List: [{ Name: "A", Class: "B" },
{ Name: "C", Class: "D" }] };
$.ajax({
type: 'POST',
url: '/{controller}/{action}',
cache: false,
data: JSON.stringify(myList),
dataType: 'json',
contentType: 'application/json; charset=utf-8'
});

Resources