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!

Community
  • 1
  • 1
Genadinik
  • 18,153
  • 63
  • 185
  • 284

1 Answers1

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.

CrayonViolent
  • 32,111
  • 5
  • 56
  • 79
  • 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 – CrayonViolent Jun 05 '12 at 17:49