Ajax error value return null - javascript

I have a function in ajax :
$.ajax({
type: "POST",
url: "#Url.Action("FiltraLevatamento", "Consulta")",
data: JSON.stringify(jsn),
contentType: "application/json",
dataType: "json",
async: true,
success: function (data) {
result(data);
$("#modalboxProcessa").modal("hide");
},
error: function (XMLHttpRequest, txtStatus, errorThrown) {
$("#modalboxProcessa").modal("hide");
$("#modalboxErro2").modal("show");
}
});
In my local machine works properly only when I publish in the server error in ajax .
Can anyone tell me what is the problem ? I have pretty much the same ajax only returning me other than data, and is running fine .

Related

Edge Browser Ajax file upload call WebApi is not working

Edge Browser Issue : Ajax Call to web API is not working in Edge browser, rest other browsers its working fine including IE.
function uploadPDFajaxcall(data, url) {
$.support.cors = true;
$.ajax({
url: url,
type: 'POST',
data: data,
cache: false,
dataType: 'json',
processData: false,
crossDomain: true,
//contentType: "application/json",
contentType: false,
success: function (data, textStatus, jqXHR) {
},
error: function (jqXHR, textStatus, errorThrown) {
console.log('ERRORS: ' + textStatus);
}
});
}
Actual: Edge browser getting Error (catch). rest all browsers working as expected.
Expected: It should hit the web API successfully

Calling web service from code behind instead of javascript

I have a javascript code that calls a web service from another server, it's working, but i need to call it from code behind due to an http call request issue, following my code :
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://10.8.111.12:7181/CatchEventLink.asmx/CollectDataLink",
data: JSON.stringify({ "pDataDictionnary": lDataCollected }),
dataType: "json",
async: true,
success: function (data, textStatus) {
if (textStatus == "success") {
//alert('success');
}
},
error: function (exception) {
//alert('Exeption : ' + exception);
}
});
Any suggestions please??

ajax request not working in google chrome - net::ERR_INCOMPLETE_CHUNKED_ENCODING

I have a plain html page and I write some javascript code that use jquery ajax request. The ajax request sends to server successfully in firefox and IE, but does not work in google chrome! When the ajax request sent, chrome console shows net::ERR_INCOMPLETE_CHUNKED_ENCODING error. I don't know How can I solve this strange problem. Here is my ajax code:
var data = {};
data['type'] = "email";
data['value'] = "test#gmail.com"
$.ajax({
headers: {
Accept: "application/json; charset=utf-8",
"Content-Type": "application/json; charset=utf-8"
},
type: "POST",
url: "/testUrl",
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function(result) {
alert("success");
},
error: function(data) {
alert("error");
},
failure: function(errMsg) {
alert("failure");
}
});
I tested plain ajax request with XMLHttpRequest javascript object, but also has above problem.

AJAX post is empty on the server side (PHP)

I am making an AJAX request to a PHP controller, by using jQuery ajax, but when trying to get the posted data with PHP the $_POST is empty. Below is the actual function:
function GetSeriesForManufacturer(manuf) {
selectedmanufacturer = manuf;
//Make an AJax Call For Getting Series Of Manufacturer
var series = null;
$.ajax({
type: "POST",
url: url,
data: "{manufacturer:'" + selectedmanufacturer + "'}",
contentType: "application/json", //; charset=utf-8",
dataType: "json",
cache: false,
async: false,
success: function (response) {
//remove loading gif
$(".loading").hide();
//Append Data
AppendSeries($.parseJSON(response.text), selectedmanufacturer);
//Custom Scrollbar Call
$('.MatchingSeries ul').mCustomScrollbar();
},
error: function (XMLHttpRequest, textStatus, errorThrown) { }
});
}
Thanks in advance!
First, you don't need to stringify data. Just send object literal is ok.
data: {manufacturer: selectedmanufacturer},
Second, you don't need this line:
contentType: "application/json",
Let jQuery do the encoding for you:
$.ajax({
type: "POST",
url: url,
data: {
manufacturer: selectedmanufacturer
},
contentType: "application/json", //; charset=utf-8",
dataType: "json",
cache: false,
async: false,
success: function (response) {
...
},
error: function (XMLHttpRequest, textStatus, errorThrown) { }});

AJAX success call back not working

Here is the code I am using to access my web API controller named Owner; the success function is not being called. Any ideas?
$.ajax({
type: "GET",
url: 'http://localhost:26533/api/Owner',
contentType: "application/json",
dataType: "jsonp",
success: function (response) { alert("yes"); }
});
Remove the contentType and dataType and check the response..
Here an example:
$.ajax({
type: 'GET',
url: 'http://localhost:26533/api/Owner',
success: function(data){
alert(data);
},
error: function(xhr, type, exception) {
// if ajax fails display error alert
alert("ajax error response type " + type);
}
});
With this you can see what's wrong...

Categories