Deep Translate

פרמיום
על ידי Serge | מְעוּדכָּן 20 дней назад | Translation
פּוֹפּוּלָרִיוּת

9.9 / 10

חֶבִיוֹן

1,223ms

רמת שירות

99%

Health Check

N/A

חזרה לכל הדיונים

400 Bad Request

Rapid account: Arnavkatyal 03102012
arnavkatyal03102012
год назад

My code:
let settings = {
async: true,
crossDomain: true,
url: “https://deep-translate1.p.rapidapi.com/language/translate/v2”,
method: “POST”,
headers: {
“content-type”: “application/json”,
“X-RapidAPI-Key”:
“1f610dfd9emsh8dad20c2f3898fdp16427djsn249900a99a9c”,
“X-RapidAPI-Host”: “deep-translate1.p.rapidapi.com”,
},
processData: false,
data: {
q: “Hello World!”,
source: “en”,
target: “es”,
},
}
const setdata = (text, target) => {
settings.data.q = text
settings.data.target = target
}
// let t;
const req = () => {
let ajax = $.ajax(settings)

    ajax.done(function (response) {
      $("textarea")[1].textContent =
        response.data.translations[0].translatedText
    })
  }
  $("#translate").on("click", () => {
    setdata($("#textarea").text(), $("#select option:selected").val())
    req()
  })
Rapid account: Gatzuma
gatzuma Commented год назад

I’d like to be sure there really right printed JSON there, which should look like this:

{ “source”:“en”, “target”:“es”, “q”:“Hello World!” }

with all field names double-quoted

Rapid account: Gatzuma
gatzuma Commented год назад

Hey, could you please show how exactly looks the POST request body and which headers are set there?

From the first sight the code looks OK, but I’m not so confident with JS and how it form the final request.

הצטרף לדיון - הוסף תגובה למטה:

התחבר / הירשם כדי לפרסם תגובות חדשות