0

I am working on a FireFox Extension... I would look to make a http post to a desired url.

I am looking to do something similar to this post. HTTP POST in javascript in Firefox Extension
I have also read through Mozilla including... https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Sending_forms_through_JavaScript "Using FormData bound to a form element"

The URL(Lambda Function) I am sending this to is not receiving the request. I have not been heavily exposed to javascript. Also, I don't know if there is something I am missing since this is being built as a Firefox Extension.


I have implemented this is my code.

    document.addEventListener("submit").addEventListener("click", function(){
      var params = "test=test"
      var req = new XMLHttpRequest(); 
      req.open('POST', 'https://sdlurjb3zi.execute-api.us-west-2.amazonaws.com/contMang');
      req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      req.send(params);
    });

The Project is format as so

    chcFolder
      manifest.json
      tabchc.
         --dasForm.css
         --dasForm.html
         --dasForm.js
Mason SB
  • 445
  • 1
  • 3
  • 13
  • There's a whitespace in your url after `.us.west-` maybe that's why. – Iskandar Reza Jan 25 '19 at 20:49
  • ah thanks for noticing that, but it is an error from formatting the code in SO. Thanks, i'll fix that – Mason SB Jan 25 '19 at 20:50
  • Are you getting an error message? – Mo A Jan 25 '19 at 20:52
  • Can you post what you are getting in your F12 developer tools network tab when you hit the endpoint? That would help demystify things. – Iskandar Reza Jan 25 '19 at 20:52
  • @MoA , no errors. Nothing changes with the pop-up. – Mason SB Jan 25 '19 at 20:57
  • @IskandarRezaRazali Dev Tools (while on www.google.com) The Number of responses does not change. the Alert in the code fires and displays, but not the XMLHttpRequest... Perhaps I'll make a repo.. – Mason SB Jan 25 '19 at 21:04
  • Does it work in Postman? If yes, are you using AWS API Gateway? If so, you probably need to enable CORS. – Mo A Jan 25 '19 at 21:07
  • @MoA yes, and there are no CORs issue. Just a simple url that should return a 200 response. This can be tested by running this in the command line.. curl -i -X POST -H 'Content-Type: application/json' -d '{"name": "New item", "year": "2009"}' https://sdlurjb3zi.execute-api.us-west-2.amazonaws.com/contMang – Mason SB Jan 25 '19 at 21:20
  • @MasonSB I tried calling the service using Postman and it works. You're attempting to run the code on a client-side form, right? If that's the case, why do you think it's not CORS related? It could be a simple URL, but if your Gateway doesn't have CORS enabled, then it won't work. I am not 100% sure this is the issue here, but it might be. – Mo A Jan 25 '19 at 22:38
  • @MoA This is my first FireFox "extension"/add-on/plug-in. It works as a pop-up. From what I have read on the documentation you need to set permissions which i have done. The Lambda function is open so it won't give a CORS issue... I am beginning to believe these extensions can't make outbound request... – Mason SB Jan 25 '19 at 22:45
  • @MasonSB I see. Curious, does it work with a public GET request such as `https://jsonplaceholder.typicode.com/todos/1` ? – Mo A Jan 25 '19 at 22:48

0 Answers0