1

I have been looking at this SO post: JavaScript post request like a form submit

and I have a slightly different situation. Have this curl command which works:

curl -v -X POST -H "application/json" -H "Content-type: application/json" -d 'some json' http://127.0.0.1:9010/api/kpi

but now I need to put this sort of a thing into a JavaScript file and it obviously breaks.

Could someone please help me create this in JavaScript?

Thanks!

1 Answer 1

2

javascript doesn't have curl, the closest equivalent would be AJAX. But you cannot make a post (ajax) request in javascript to a domain other than the current page's domain, as this is considered cross-site scripting.

Sign up to request clarification or add additional context in comments.

1 Comment

note: one "workaround" is to make an ajax request to the same domain your page the page is on, and perform the curl server-side and return the results back to javascript in the ajax response

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.