/ / कोणीय से jQuery के लिए एक आराम एपीआई कॉल का अनुवाद - जावास्क्रिप्ट, jquery, कोणीय, आराम

बाकी एपीआई कॉल को कोणीय से jQuery - जावास्क्रिप्ट, jquery, कोणीयज, बाकी में अनुवाद करना

माफी अगर शब्द अजीब से, लेकिन मुझे बनाना हैjQuery का उपयोग करके एक बाकी एपीआई कॉल। मैंने पहले ही angularJS का उपयोग करके कॉल किया है, लेकिन इस मामले के लिए मैं इसका उपयोग नहीं कर सकता हूं। मैंने इसे jQuery में अनुवाद करने की कोशिश की, लेकिन मुझे वही परिणाम नहीं मिल रहे हैं। क्या मैं कुछ गलत कर रहा हूं या मुझे जानकारी याद नहीं है? मैं jQuery के लिए काफी नया हूँ इसलिए मुझे लगता है जैसे कि मैं कुछ महत्वपूर्ण या कुछ गलत समझ रहा हूँ।

कार्य कोड angularJS के साथ:

var req = {
method: "POST",
url: "https://fakeurl.com/rest/v1/portal/user/" + $scope.email.value,
headers:{
"Content-Type": "application/json",
"Header_1": "Yes",
"x-access-token": "glsFromWebsite" //$scope.authInfo.token
}
};

restCall($http, req).then(function (res) {

// check for error even though 200 response
if (res.error) {
console.error("Error reported...");
} else {
`         //enter success code here
}
});

var restCall = function(http, req) {
var _url = getBaseUrl() + req.url;
req.url = _url;

return new Promise(function(fulfill, reject) {
try {

http(req).then(function (res) {

// check for error even though 200 response
if (res.data.error) {
if (res.data.error === "601") {
console.error("Token is invalid or has expired");
} else {
console.error("Error from end point: " + res.data.error);
}
}
fulfill(res.data);

}, function(err) {
console.error("Error calling rest endpoint",err);
reject();
});

} catch (ex) {
console.error("Exception calling rest endpoint",ex);
reject(ex);
}
});
};

मेरा असफल jQuery कोड:

var processCreate = function (email) {

$.ajax({
url: "https://fakeurl.com/rest/v1/portal/user/" + email.value,
type: "POST",
headers: {
"Content-Type": "application/json",
"Header_1": "Yes",
"x-access-token": "glsFromWebsite" //$scope.authInfo.token
},
success: function (res, a, b) {
if (res === "NOT FOUND") {
//code that runs when this case is true
} else {
//code that runs when this case is false
}
},
error: function () {
console.error("Error...");
}
});
}

उत्तर:

उत्तर № 1 के लिए 1

इस तरह से अजाक्स कॉल करने का प्रयास करें

var processCreate = function (email) {
var authHeaders = {};
authHeaders.Authorization = "Bearer " + "glsFromWebsite";

$.ajax({
url: "https://fakeurl.com/rest/v1/portal/user/" + email.value,
type: "POST",
cache: false,
dataType : "json",
contentType: "application/json; charset=utf-8",
headers: authHeaders,
success: function (data) {

//console.log(data);
if (data === "NOT FOUND") {
//code that runs when this case is true
} else {
//code that runs when this case is false
}
},
error: function (xhr) {
console.log(xhr);
}
});
}