简体   繁体   中英

error in sending a post request using ajax

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); } }); 

   $.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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM