Guest User

Untitled

a guest
Apr 15th, 2018
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. XMLHttpRequest cannot load http://localhost:8080/hvTool2_Ang2/src/app/php/pullData.php. Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.
  2.  
  3. <IfModule mod_headers.c>
  4. Header set Access-Control-Allow-Origin: *
  5. </IfModule>
  6.  
  7. header('Access-Control-Allow-Origin: *');
  8. header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
  9. header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
  10.  
  11. getData(routing: string, functionindex: number, dataarray) {
  12. var sentData = JSON.stringify(dataarray);
  13. var sentArray = [routing, functionindex, sentData];
  14. var returnedJSON;
  15. var url;
  16. if (this.dev_env == true){
  17. url = this.devPHPfolderURL;
  18. }
  19. else{
  20. url = this.prodPHPfolderURL;
  21. }
  22. let headers = new Headers();
  23. //headers.append('Content-Type', 'application/json'); //CORS issue
  24. headers.append('Content-Type', 'text/plain'); //no CORS issue
  25.  
  26. return this.http.post(url, sentArray)
  27. .subscribe(
  28. result => returnedJSON = result,
  29. () => console.log("Failed..."),
  30. () => console.log("Completed: " + returnedJSON)
  31. );
  32. }
  33.  
  34. $myServer = "SERVER"; //Actual variable answers were changed for this post.
  35. $myUser = "USER";
  36. $myPass = "PASS";
  37. $myDB = "DATABASE";
  38.  
  39. // connection to the database
  40. $connection = odbc_connect("Driver={SQL Server};Server=$myServer;Database=$myDB;", $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer");
  41. $result = odbc_prepare($connection, $query);
  42. odbc_execute($result)or die(odbc_error($connection));
  43. odbc_close($connection);
  44. odbc_fetch_array($result);
  45.  
  46. header('Access-Control-Allow-Origin: *');
  47. header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
  48. header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
  49.  
  50. while ($info = odbc_fetch_array($result)) {
  51. $total[] = $info;
  52. }
  53.  
  54. echo json_encode(odbc_fetch_array($total); //To send to JavaScript
  55.  
  56. headers.append('Content-Type', 'text/plain');
  57.  
  58. headers.append('Content-Type', 'application/json');
  59.  
  60. this.reqOpts = { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }};
Add Comment
Please, Sign In to add comment