Guys,
It took me three days to solve one simple problem which was caused due to ajax post form posting data to .asmx service webmethod. This error usually happens when there is an implementation of dynamic/stati compression in the project for ex. gzip or deflate compression. The code which worked is given below:
$.ajax({
url: 'test.asmx',
dataType:"json",
contentType: false,
processData: false,
type: 'POST',
data: formData,
success: function (data) {
console.log(data);
data = data.d;
console.log('inside success response Text is '+this.responseText);
console.log(data);
console.log('Success');
checkData(this.responseText);
},
error: function (a, b, c) { console.log('Error');checkData(a.responseText); console.log(a); console.log(b); console.log(c); }
});
The problem was occurring due to Gzip compression in my asp.net project. This caused content decoding error which is not supported when we post a form as the form values are not compressed. This caused a huge blow to my work which I was not able to work around. The solution for this was to use a asp.net handler instead of web service as the web service takes the data in json or other forms. However the code above required a form submit which was due to the file upload in my form. I replaced the above code with
$.ajax({
url: 'Handler.ashx',
dataType:"json",
contentType: false,
processData: false,
type: 'POST',
data: formData,
success: function (data) {
console.log(data);
data = data.d;
console.log('inside success response Text is '+this.responseText);
console.log(data);
console.log('Success');
checkData(this.responseText);
},
error: function (a, b, c) { console.log('Error');checkData(a.responseText); console.log(a); console.log(b); console.log(c); }
});
This actually proved to be successful and the data was posted successfully.
Hope it helps!
It took me three days to solve one simple problem which was caused due to ajax post form posting data to .asmx service webmethod. This error usually happens when there is an implementation of dynamic/stati compression in the project for ex. gzip or deflate compression. The code which worked is given below:
$.ajax({
url: 'test.asmx',
dataType:"json",
contentType: false,
processData: false,
type: 'POST',
data: formData,
success: function (data) {
console.log(data);
data = data.d;
console.log('inside success response Text is '+this.responseText);
console.log(data);
console.log('Success');
checkData(this.responseText);
},
error: function (a, b, c) { console.log('Error');checkData(a.responseText); console.log(a); console.log(b); console.log(c); }
});
The problem was occurring due to Gzip compression in my asp.net project. This caused content decoding error which is not supported when we post a form as the form values are not compressed. This caused a huge blow to my work which I was not able to work around. The solution for this was to use a asp.net handler instead of web service as the web service takes the data in json or other forms. However the code above required a form submit which was due to the file upload in my form. I replaced the above code with
$.ajax({
url: 'Handler.ashx',
dataType:"json",
contentType: false,
processData: false,
type: 'POST',
data: formData,
success: function (data) {
console.log(data);
data = data.d;
console.log('inside success response Text is '+this.responseText);
console.log(data);
console.log('Success');
checkData(this.responseText);
},
error: function (a, b, c) { console.log('Error');checkData(a.responseText); console.log(a); console.log(b); console.log(c); }
});
This actually proved to be successful and the data was posted successfully.
Hope it helps!
4 comments:
I have read this article and it is really interesting for reading. You have mentioned all the related things with efficiency. Really appreciated.
Now buffalo web development service is available from Crystal Tech Solution in a professional way.
Best Programming institutes in Delhi NCR
Black Friday Kitchen Gaming Computer Deals
Black Friday Induction Burner Deals
Black Friday Washer and Dryer Deals
Digital Marketing Agency in Faridabad
SEO Company Faridabad
SEO Company in Faridabad
Digital Marketing Company in Faridabad
Xbox One Black Friday Deals
Black Friday Soundbar Deals
Black Friday Radio FM Deals
Black Friday Home Theater Deals
Post a Comment
Comments are welcome, Please join me on my Linked In account
http://in.linkedin.com/pub/ritesh-tandon/21/644/33b