Jquery Ajax multi user request - c#

I am very new into ajax and i am having a strange problem, I have created an asp.net website that have a web service within the project I am calling this web service by following ajax code:
$.ajax({
type: "POST",
url: pageUrl + "/PassData",
data: JSON.stringify({ aos_code: code }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccessCall
});
the c# code is not very complicated, basically it will get the code and call the stored procedure and return some value:
[WebMethod(EnableSession = true)]
public string[] PassData(string aos_code)
{
// calling the database and returning some data
return data;
}
And it works fine; the problem is that if two different users accessing the application in the two different computers and let say they clicking a button at the same time to call the server side function via Ajax, it will return the “500 internal server error”.
I am not sure how exactly Ajax work, is request are belong to same session or all user requesting a single function?
Hope it makes sense, and I would really do appreciate for the clarification and help.
Regards,

Error 500 indicates that something went wrong on the server side. Check your console (firebug or similar) to see what exactly happened and try to fix it. Ajax has nothing to do with it, it is simply as if two users visited the same page at the same time.

Related

asp.net api service.svc query length problems

Hello I got a service that is made for sending html mails, it will be called from a method "SendMail(data) about 1500 characters.
I access the service though JQuery with AJAX call and JSON:
var data = encodeURIComponent(JSON.stringify(dataArray));
$.ajax({
type: "GET",
url: "http://localhost:53334/Service.svc/SendMail?data=" + data,
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function () {
alert("Reklamationen er blevet sendt!");
},
error: function (err) {
alert("Kunne ikke sende reklamation! Der opstod en fejl.");
}
});
I got alot of fields and if I fill everything out it gives a 404 not found response but then if I leave some random fields empty it gets to the API and executes the method it should? So I think its about the data size. I have tried many settings in webconfig but i havent managed to find a solution.
I hope there will be someone who can help me.
You should really be using POST as indicated by Tikkes. Semantically you aren't requesting a resource from the server, so GET doesn't make sense. Also, as noted here there is a maximum length that is enforced for Urls which is what GET uses to pass params(as you can see in your code as well). POST on the other hand uses the request body to send its data. Also, as noted here POST and GET sizes are usually configurable on the server, but POST is generally much larger(2KB vs 10MB defaults) as stated in one of the answers. Hope this helps.

AJAX requests from jquery in android application to WCF Service always fails

I have an application where I fetch a list of requests made by the user based on the idNo provided. The android application uses AJAX to make a request to a .NET WCF Service which in turn returns a IEnumerable of DTO for that request.
Following is the AJAX Code:
$.ajax({
url: baseURL + "RequestStatusList/"+idNo,
cache : false,
type : "GET",
dataType : "json",
contentType : "application/json; charset=utf-8",
crossdomain : true,
success : function(data, tst, xhr) {
//do something here
},
error: function (xhr, tst, err) {
alert(' Please Try Again ' + xhr.status);
}
});
A similar piece of code works in another page in the application, where only the process in success is different, rest all is same.
Here every time the request fails and enters the error section and displays undefined/0 as error. No details about error, hence i cannot get what maybe the problem.
When I debug the server side code I get proper value in the parameter passed and a IEnumerable is formed and returned. What fails is the client side code after successful execution of server code.
Please Help.
Thanks in advance.

processing ajax post on the server using c#

I'm trying to do something that's very new to me. I've done some digging but what I've come up with only had solutions by using some kind of .aspx page to process forms.
What I'd like to do is send some form input via ajax (I'm using jquery) to the server to be processed by c#.
This is, I believe, a fairly general question. It doesn't have to do with submitting form input specifically, but more about how to send some data to be processed by c# in the backend.
I want to make an ajax POST to a certain page for processing such as this:
$.ajax({
type: "POST",
url: "****???****",
data: { name: "Bob", gender: "Male" },
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var names = response.d;
alert(names);
}
});
Now, my question is, what kind of file/page can I use for the url value in the above ajax call, that will be able to handle the POSTed data using c#?
All the examples I've seen use a .aspx page that processes the form and sends it to a .cs code-behind page. If possible, I'd like to be able to use something other than an .aspx page.
The site I'm working on is using just HTML as I'm working with angular. Is there any other way I can handle ajax on the server in a way that I can use c#?
To be very specific, I'm trying to setup a registration page where a user puts in their username and password. I need the password to be sent to the server to have a hash and salt created in C#.
Thanks, and please let me know if you need any additional information to continue.
Try this
In code behind file:Default.aspx.cs
[WebMethod]
public static void GenerateHash(string name,string password)
{
//Write logic to generate hash
}
.aspx page
$.ajax({
type: "POST",
url: "Default.aspx/GenerateHash",
data: { name: "xxx", password: "xxxx" },
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var names = response.d;
alert(names);
}
});

Dojo 1.8 web service call fails with status: 500 error code

dojo.xhrPost({
url: "Default.aspx/TestMethod",
handleAs: "json",
contentType: "application/json",
postData: dojo.toJson({ }),
load: function (result) {
debugger;
},
error: function (err) {
debugger;
}
});
That is the script I use to make a request to a WebMethod that is exposed in Default.aspx. The method is called TestMethod.
The error that I get is:
Unable to load Default.aspx/TestMethod status: 500
If you need any additional information please let me know.
*Note : I can call the method from the server side and it returns the results as intended.
I've been there. :(
Usually it is a problem with the format of the data that you are passing in. For instance, if your WebMethod has a parameter that is an int and you are passing a string, you will get a failure like this.
I would use a tool like Fiddler http://www.fiddler2.com/fiddler2/ to see what you are sending to the method.
Also turn on what ever server side logging and tracing that you have and use it. One source that is useful for 500 errors (which tend to happen before "your" server code is reached) is Asp.net health monitoring.
There is more info about setting that up and using it at http://msdn.microsoft.com/en-us/library/bb398933(v=vs.100).aspx

500 - Internal server error. how i can solve it in asp.net MVC 3 on server?

I deployed a mvc 3 project.
The server gave an error 500 - Internal server error. Nothing else.
How can I get more detail about it. How can I know the reason behind it, because there is nothing going wrong in my code in my development machine.
Since I just have FTP access, is there a way for me to create a log and get all the information about the error in detail.
are their any possible thing i can do that i can see the error in my browser. no problem because i deploy on testing domain.
You will get a 500 error if the web.config xml is invalid. Find out if is invalid by opening IIS Manager, and for the site double click on one of the features (Authorization, HTTP Redirect). If the xml is invalid, it will display a message box with an error and a line number.
If the web config is ok, configure customErrors so you can the errors.
http://msdn.microsoft.com/en-us/library/h0hfz6fc(v=vs.100).aspx
This might display some more detailed information.
Please make sure is ASP.Net MVC installed on the server? or Is the correct version of IIS installed on the server?
Check that the data is out of ajax like data_.
var data_ = { indexNum: index };
$.ajax({
type: "POST",
url: "/Home/ExamsById",
data: data_,
dataType: 'json',
success: function (response) {
$(".cont-exams").slideToggle();
}
});
Check that the data is out of ajax like data_.
var data_ = { indexNum: index };
$.ajax({
type: "POST",
url: "/Home/ExamsById",
data: data_,
dataType: 'json',
success: function (response) {
$(".cont-exams").slideToggle();
}
});

Categories

Resources