I am using vb.net 2.0 and asp.net in my project.
I am sending ajax request from a page to get response.
$.ajax({
type: "POST",
url: "GetMyData.aspx?i=2",
data: '{ugData: \"10\"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert(response.d);
return false;
},
failure: function (response) {
alert("Failed");
}
});
In this code, after ajax request I can see that the variable "ugData" is in the Request Payload in Developers tool.
Can any one help me out How can i able to read this "ugData" variable value in my Page "GetMyData.aspx".
Thank You..
Related
i got a problem in meteor when i try to make a cross origin call.
when i make the call using Ajax.
$.ajax({
type: 'GET',
url: signoutUrl,
async: false,
contentType: "application/json",
dataType: 'jsonp',
success: function (nullResponse) {
console.log('success');
},
error: function (e) {
console.log('error in HTTP :: >>>>' + JSON.stringify(e));
}
});
it works fine with no problem. but when i am using meteor's HTTP.call method for the same Http request it sent me the error.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
i set the parameters and header in meteor Http.call are
HTTP.call(method, URL,
{params: {
async: false,
contentType: "application/json",
dataType: 'jsonp'},
headers:{'Access-Control-Allow-Origin':'https://www.google.com/*'}
}, function (err, result) {}
but when i check the request. i found the header is like
access-control-request-headers:access-control-allow-origin
so, help me where i am wrong in this HTTP request and how to resolve it
i am going to develop a new application and i have decided to use asp.net mvc4 framework.
my project is very large and i would to make a professional work,now my problem is how to use ajax for such an application.
when i tried to think to use j query ajax i found that i'll make ajax request for each entry form and it would take more time.
<script type="text/javascript">
$(document).ready(function () {
var sURL = '/AjaxTest/FirstAjax';
$.ajax({
type: "POST",
url: sURL ,
data: {
//Form data to submit to controller .....},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: successFunc,
error: errorFunc
});
function successFunc(data, status) {
alert(data);
}
function errorFunc() {
alert('error');
}
});
</script>
You can make some service function that does ajax requests and receives url and data to send.
dataService=function(url,data)
{
return $.ajax({
type: "POST",
url: url ,
data: data
contentType: "application/json; charset=utf-8",
dataType: "json",
});
};
Your dataservice method (ajax requests) returns promise object which means you can do something like:
dataService("firstUrl","firstAjaxCallData")
.then(function(){ console.log("this happens after sucessfull ajax call")});
Looks like it just doesnt want to work...
# Webservice:
<ScriptMethod(UseHttpGet:=False, ResponseFormat:=ResponseFormat.Json), WebMethod()> _
Public Function LoginDB(ByVal user As String, ByVal pass As String) As String
global.user = user
global.pass = pass
If (<<lots of code to check if user is valid>>) Then
Return "1"
Else
Return "0"
End If
End Function
The webservice DOES work, if the user is valid, returns 1 otherwise 0. But I always get it as XML
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">"0"</string>
#Jquery:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Services/Autenticacao.asmx/LoginDB",
data: "{'user':'ale','pass':'123'}",
dataType: "json",
success: function(data) {
alert(data);
},
.....
Anyone?
You need to post your jQuery, but are you using the getJson jQuery method? If not you need to explicitly set the correct data type:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebService.asmx/WebMethodName",
data: "{}",
dataType: "json"
});
Or use the getJSON method:
$.getJSON('WebService.asmx/WebMethodName', function(data) {
//Do something with JSON response (data)
});
If you want your webservice to return JSON
asked and answered... How to return JSON from a 2.0 asmx web service
I am simply learing Ajax with jQuery and have a simple page method that takes in a parameter and returns a string. For some reason, I am not getting the return string but I am getting to my 'success' message:
$(document).ready(function() {
$.ajax({
type: "POST",
url: "testFormMatt.aspx/sayHello",
contentType: "application/json; charset=utf-8",
data: '{"name": "matt"}',
dataType: "json",
success: function(msg) {
$.jGrowl('The web service has been successfully called');
$('#result').append(msg);
}
});
});
When you call append, you need to specify the property of the JSON object that you want to append.
So if your page is returning:
{ message: "Hello, Matt" }
Then you'd need to call append like this:
$("#result").append(msg.message);
If your page is not returning JSON, then you need to take the dataType: "json" out of the $.ajax call. The dataType parameter is for specifying the expected data type of the response, not the data type of the request.
is it possible to call a webservice that accepts 5 string parameters without sending via json? (is this recommended) I have created a webservice with a method that accepts 5 string params.. and i have my jquery
$.ajax({
type: "POST",
url: "Service.aspx/CreateClient",
data: "{}",
contentType: "application/json; charset=utf-8", //// ERMMM ???
dataType: "json", // ERMMM?
success: function(msg) {
alert(msg.d);
},
error: function() {
alert('error');
}
});
The old way without using jquery was to do this
this.para.add("Name", name);
this.para.add("ClientNum", clnum);
this.para.add("Email", email);
this.para.add("Register", register);
this.para.add("Message", message);
SOAPClient.invoke(this.url, "MyService.aspx/CreateClient", this.para, true, this.completeDone, this);
At the other end it lands and fills in all parameters....
What is the recommended way?
why not use querystring variables and avoid the overhead of the SOAP protocol?