I have two Ajax calls but one of the Ajax calls are returning net::ERR_SPDY_PROTOCOL_ERROR.
The Ajax call urls are coming from WordPress Woocommerce RestApi.
When I run chrome in mode - chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security - the error disappears and everything is working correctly.
Error
Ajax call that is not working:
$.ajax({
url: "https://krii.000webhostapp.com/wp-json/wc/v2/products/categories?per_page=99",
success: function(json){
console.log("Success", json);
$.each(json, function (index, categories) {
//console.log(categories);
catego.push({Cat_Name: categories.name});
//console.log(catego);
$('select#categories2').append('<option data-id="> categories.id">'+categories.name+'</option>');
});
},
error: function (XMLHttpRequest, textStatus, errorThrown){
console.log(textStatus,errorThrown)
},
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Basic ' + btoa('ck_...:cs_...'));
},
type: 'GET',
contentType: 'json'
});
Ajax call that is working:
$.ajax({
url: "https://..../wp-json/wc/v2/products/categories?per_page=99",
success: function(json){
console.log("Success", json);
$.each(json, function (index, categories) {
//console.log(categories);
catego.push({Cat_Name: categories.name});
//console.log(catego);
$('select#categories').append('<option data-id="> categories.id">'+categories.name+'</option>');
});
},
error: function (XMLHttpRequest, textStatus, errorThrown){
console.log(textStatus,errorThrown)
},
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Basic ' + btoa('ck_...:cs_...'));
},
type: 'GET',
contentType: 'json'
});
How exactly I can fix this, cause it does not work on mobile device.
This error ERR_SPDY_PROTOCOL_ERROR is found in Google chrome. With latest updates of google chrome it is depracted. This protocol was added for faster web load and security. You can learn more from how-to-fix-err_spdy_protocol_error-in-google-chrome-2019
Related
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
I'm making a cross domain ajax call. When I heat the link directly from my browser, I get the json strin as follows:
But when I'm making an ajax call to this same URL, I'm not getting the json in my response. My ajax request is as follows:
$.ajax({
url: "http://172.16.201.14:801/api/apiclearing?trackNo=" + $scope.BillClearingModel.BillTrackingNo + "&&tokenNo=~Ice321",
dataType: 'jsonp',
success: function(response) {
console.log(response);
alert("Success");
},
error: function(response) {
console.log(response);
alert("Failed");
}
});
What Im getting in console is as follows:
Full Object is as follows:
What I'm missing here? Thanks.
Would you mind trying this:
var datastring = { "trackNo" : "160822000037" };//try this
//var datastring = "trackNo=160822000037"; //or this
$.ajax({
type: 'POST',//you may try the GET type
url: "https://172.16.201.14:801/api/apiclearing",
dataType: 'json',// try jsonp as well
data: datastring,
contentType: 'application/json',
crossDomain: true, //newly added
success: function(data, status, jqXHR) {
console.log(data);
console.log(status);
console.log(JSON.stringify(data));//to string
alert("Success");
},
error:function(jqXHR, textStatus, errorThrown) {
alert("Status:"+ textStatus + " Error:" + errorThrown);
}
You may consider as well to add Access-Control-Allow-Origin to your server like Access-Control-Allow-Origin: http://yourdomain-you-are-connecting-from.com in php
In JQuery AJAX while calling a REST API, As per the functionality the negative use cases needs to be logged.
In the chrome console this can be seen
net::ERR_ADDRESS_UNREACHABLE
net::ERR_NETWORK_CHANGED
net::ERR_NAME_NOT_RESOLVED
how to capture these exact errors in the error callback or any other means
The JQuery AJAX Code is
$.ajax({
type: 'GET',
url: <my url>,
contentType:'application/json',
dataType:'text',
beforeSend: function (xhr) { },
data: "",
success: function (responseData, textStatus, jqXHR) {
//success code
},
error: function (responseData, textStatus, errorThrown) {
console.log(arguments);
//here I need to capture the exact network error
}
When i run url of following code in Firefox poster it runs successfully, but when i try to run with help of $.ajax in my js file of mobile app it gives me "ERROR". why?
(order_id is not the issue)...
$('#page_custinfo').bind('submit',function(){
$.ajax({
url: "http://localhost/putDetails.php?order_id=3&fname=seth&lname=rahul&email=ol#gmail.com&s_add1=karveroad&products=nokia&order_status=pending&order_total=1000&city=pune&postal_code=033&country=india",
type: 'GET',
contentType: 'application/x-www-form-urlencoded' ,
success : function (serverResponse) { alert("success"); },
error : function (jqXHR, textStatus, errorThrown) {alert("ERROR"); }
});
});
I have a php script, which return serialized in php data. And I try to receive this data by using $.ajax() method from jQuery 1.7. Here is the example.
$.ajax({
url: 'http://input.name/get.php?do=lookup' + '&domain=twittorama&tlds=.ru,.com,.net,.comf.ru',
type: 'GET',
dataType: 'text',
cache: 'false',
complete: function(res) {
alert('COMPLETE() done');
console.log(res);
}
});
In console I see only
Object { readyState=0, status=0, statusText="error"}
So, what I do wrong? Could you help me please?
UPD
Interesting notice: if I use JSONP dataType request can receive data, but can't process it.
Here is an example.
$.ajax({
url: 'http://input.name/get.php?do=lookup',
data: 'domain=twittorama&tlds=.ru,.com,.net,.comf.ru',
dataType: 'jsonp',
cache: false,
success: function(data) {
alert("Data: "+data);
},
error: function(jqXHR, textStatus, errorThrown) {
alert("Error: "+textStatus);
console.log(jqXHR);
}
});
Instead of complete: use success: then res will be the returned data from your ajax request.
Remember to use error: as well incase there is an error with you call, as it seems that there might be in your console output.
Code:
$.ajax({
url: 'http://input.name/get.php?do=lookup',
data: 'domain=twittorama&tlds=.ru,.com,.net,.comf.ru',
cache: false,
success: function(data) {
alert("Data: "+data);
},
error: function(jqXHR, textStatus, errorThrown) {
alert("Error: "+textStatus);
console.log(jqXHR);
}
});
Your code is probably fine, but you're trying to violate the same origin policy. Basically, if your site is http://aaa.com/, you cannot make AJAX called to http://bbb.com/.
There are a few ways around it:
Getting around same origin policy in javascript without server side scripts
But most of them require that both sides play nice.
The response is the second parameter of complete function:
$.ajax({
url: 'http://input.name/get.php?do=lookup' + '&domain=twittorama&tlds=.ru,.com,.net,.comf.ru',
type: 'GET',
dataType: 'text',
cache: 'false',
complete: function(res,response) {
alert('COMPLETE() done');
console.log(response);
}
});
More info: http://api.jquery.com/jQuery.ajax/
You should also consider using JSON, not php serialized data