0

I'm trying to send a post request using ajax but I keep getting the following error :

XMLHttpRequest cannot load http://192.168.1.123:8080. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

here is my code

$.ajax({
      type: "POST",
      url: "http://192.168.1.123:8080",
      data: JSON.stringify([{"VisitorName ": " "+document.getElementById("VisitorName ").value}
    ]),

      contentType: "application / json ",
      crossDomain: true,
      dataType: "json",
      success: function (data) {
                alert(data);
      },
      failure: function (errMsg) {
                alert(errMsg);
      }
 });
nero
  • 37
  • 8
  • This is CORS error the server is not allowing any other clients other than same domain for request see this for more info http://stackoverflow.com/questions/25923796/cors-error-with-jquery – Vinod Louis Dec 09 '16 at 11:11
  • Also your code has some syntax mistakes. Like on the `url`, you don't close the `"`, a `,` thrown in the code in `data` etc. – Ionut Necula Dec 09 '16 at 11:14

1 Answers1

0
   $.ajax({
      type: "POST",
      url: "http://192.168.1.123:8080,
                data: JSON.stringify([
                {
                    "
      VisitorName ": "
      "+document.getElementById("
      VisitorName ").value,
      }

From what I can tell the comma next to value is causing a syntax error. Also within the code you do not close the " for "http://192.168.1.123:8080

Ryan_
  • 64
  • 1
  • 9