Home>
ScrapboxI want to access the API of the service by GET communication of Ajax, but it does not work due to CORS error.
This articleAccording to Scrapbox, the credential (authentication information) is set in the cookie, so you can get the data by using it.
I got the cookie itself, but I don't know how to pass it in Ajax.
It would be greatly appreciated if you could teach me how to pass credentials with Ajax.
For now, I wrote the following code and tried to execute it, but the communication failed.
const api_url ='***';
$.ajax({
type: "GET",
url: api_url,
xhrFields: {
withCredentials: true
}
}).done(function (data, textStatus, jqXHR) {
console.log("done");
}).fail(function (jqXHR, textStatus, errorThrown){
console.log("failed");
});
-
Answer # 1
Related articles
- how to solve 2x3 puzzles using javascript
- javascript - i want to eliminate error 404
- javascript - i got the error these relative modules were not found while using vue router
- i want to put an error bar using standard error (sem) in ggplot2
- javascript - i want to connect to a ble device using react native's ble manager
- javascript - using the button setattribute that can be pressed only once
- java - error when connecting to sql anywhere using sajdbc4 on linux: invalid odbc handle
- javascript - i want to make margin adjustment when using flex work in ie
- javascript - how to write when using multiple arrow functions
- javascript - i want to post using ajax in django and rewrite the db value
- javascript - i want to use the js code published on another site, but i get an error
- javascript - calculate using foreach
- javascript - [js] i want to get all the dates in the specified period using the dayjs library
- i want to copy a simple game using javascript
- javascript - [gas] write to a spreadsheet using a shortcut
- ruby - i want to solve the n + 1 problem when using rails where method in loop processing
- javascript - cors error when accessing the server set up by express from the server set up by create-react-app cannot be resolve
- javascript - i want to replace any character at the end of a sentence using replace
- [python] i don't know how to solve the error
- github - i am a beginner git push can't solve the error! help me!
Related questions
- javascript : AJAX requests, JS and PHP [duplicate]
- javascript : Output and immediately insert data into the database
- javascript : How can I split an object into parameters for sending a POST request via AJAX?
- javascript : jquery send ajax only 1 request
- javascript : Issue with https protocol and AJAX
- javascript : How to send request to server as json
- javascript : How to delete a row from a database table using Ajax, without reloading the page?
- javascript : How to remove a row from a table?
- javascript : How to compress data on AJAX request?
- javascript : Change language with saving
The method in the referenced article is a method that cannot be used in JavaScript.
The method of the article is to get the authenticated cookie and embed it in the Python script source.
In the case of JavaScript, cookies cannot be specified from scripts (reference). WithCredentials: true described in the code of the question sentence specifies that the cookie originally set in the browser is also sent by AJAX, but even if the cookie is set on the browser side, if there is no permission on the API side can not use.
So, I think this method has no choice but to give up. It may be possible with other methods, but I think it's difficult if it is not an API prepared for JavaScript.