Unable to send large data in Jquery ajax call - c#

Hi I am developing MVC4 application. I am saving values to Database. I am getting below error.
The request filtering module is configured to deny a request where the query string is too long.
I am making ajax call and sending data as Json as below.
$.ajax({
type: "POST",
cache: false,
url: '/UploadDocument/SubmitDoc?JsonValue=' + JSON.stringify(SaveUpload) + '&gridData=' + strOrderArr,
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: {
'VerificationToken': forgeryId
},
success: function (response) {}
});
Web.config
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
May i know am i following good approach to handle above scenario when posting huge data to database? Thanks in advance.

It's a POST Request yet you're passing data in Query string!
Pass data in Data parameter:
$.ajax({
type: "POST",
cache: false,
url: '/UploadDocument/SubmitDoc',
data: JSON.stringify({ JsonValue: SaveUpload, gridData:strOrderArr }),
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: {
'VerificationToken': forgeryId
},
success: function (response) {}
});

Related

Posting Multipart and string content web API using Ajax in Asp.net

I have multipart content web API. which is working fine.and tested in postman.
Now i am trying to consume that web api in my asp.net web application using ajax post method. I referred some coding in google and applied. but it shows error finally. i don't know what's the misake i am doing. I am using .Net Framework 4.5. My coding and postman execution of my api as Below .
var data = new FormData();
jQuery.each(jQuery('#fileupload')[0].files, function (i, file) {
data.append('file', file);
});
data.append('siteCode', 'HQ');
data.append('phoneNumber', '95878784XXX');
data.append('customerCode', 'C001');
data.append('notificationFlag', '1');
$.ajax({
type: 'POST',
url: SequoiaUri + "api/profilePicture",
contentType: "application/json; charset=utf-8",
data: data,
dataType: "json",
Cache: false,
processData: false,
success: function (data) {
alert("Picture Uploaded Successfully!");
}
Can anyone help me what's the error in my ajax post method...
try this:
$.ajax({
url: SequoiaUri + "/api/profilePicture",
data: data,
type: 'POST',
//enctype: 'multipart/form-data', // try if still is not working
contentType: false,
processData: false,
success: function (data) {
alert("Picture Uploaded Successfully!");
},
.....

how to set caching for ajax request and response

I'm working with ajax request and I received JSON object as a response from AJAX.
Now I'm trying to cache that JSON object and how to get data from cache.I want to show the cache data from next request to the server with same request with same parameter values.
self.categorySelected = function (selectedCategory, event) {
$.ajax({
url: '/services/ShopService.asmx/XGetRefurbishedproducts',
data: JSON.stringify({ displayName: itemDisplayName, categoryid: selectedCategory.CategoryId(), language: lang }),
type: "POST",
dataType: "json",
cache: true,
contentType: "application/json; charset=utf-8",
beforeSend: function () { $(event.target).prop('disabled', true); }
}).done(function (data) {
//sample
})
}

jQuery Calls to .NET WebMethod Working Out of Order

I am using lot of .NET WebMethod calls in my web application using jQuery. My calls are not working in the expected order. The first time the page loads it works fine, and after reloading the page, the WebMethod calls are disordered. How do I make it always work one by one in the expected order?
I am using jQuery $.ajax():
$.ajax({
type: "POST",
url: "",
data: '',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) { },
error: function (msg) { alert(msg.error); }
});
Add async: false option in ajax. By default Ajax make async call hence order is not guaranteed.
$.ajax({
type: "POST",
async : false, // Add this
url: "",
data: '',
contentType: "application/json;
charset=utf-8",
dataType: "json",
success: function (response) { },
error: function (msg) { alert(msg.error); }
});

Ajax URL - Incorrect .net #c

Been following some tutorials, as i'm learning C#, however was just attempting to make an ajax call to the server, i'm using my localhost.
As far as I can tell i'm doing its right, but it's obviously not.
Maybe it my folder structure or just the name of the file.
The Default.aspx file is at the project root
Here is my ajax call
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Default.aspx",
dataType: "json",
data: "{'FirstName':'test','LastName':'test1','City':'test3','EmailID':'test4'}",
success: function (data) {
console.log("Woo!");
},
error: function (result) {
console.log("fail!");
}
});
I know eventually it will have to call a method within the file, but its not even finding it at the moment.
Thanks in advance, James
You can use controller Home and create the one action.
Example:
public ActionResult FirstAjax()
{
return Json(true, JsonRequestBehavior.AllowGet);
}
After that your jquery ajax is:
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "Home/FirstAjax",
dataType: "json",
data: "",
success: function (data) {
console.log("Woo!");
},
error: function (result) {
console.log("fail!");
}
});

Unable to pass data to method

I am trying to use AJAX with ASP.NET for the first time - by trying to pass the following data to a WebMethod in my corresponding aspx page:
$.ajax({
type: "POST",
url: "myurl.aspx/SaveScreen",
data: "{'data': " + JSON.stringify(arrayRows.data) + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg.d);
}
});
Here is my WebMethod in the aspx page. I have tried passing a simple data object which just contained one key and value, which worked successfully. When attempting to pass this object, I get an error stating that there is an internal server error with code 500.
What could I be doing wrong?
Try this:
data: {"data": JSON.stringify(arrayRows.data)}
Try this :
data: "{data: '" + JSON.stringify(arrayRows.data) + "'}"
You could wrap the data string in quotations:
$.ajax({
type: "POST",
url: "SpecifyPositioning.aspx/SaveScreen",
data: "{'data': '" + JSON.stringify(arrayRows.data) + "'}", //Added ' around JSON.stringify to pass string instead of object
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg.d);
}
});
This however would be a cleaner solution:
data: {"data": JSON.stringify(arrayRows.data)},

Categories