Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- <IfModule mod_headers.c>
- Header set Access-Control-Allow-Origin: *
- </IfModule>
- header('Access-Control-Allow-Origin: *');
- header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
- header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
- getData(routing: string, functionindex: number, dataarray) {
- var sentData = JSON.stringify(dataarray);
- var sentArray = [routing, functionindex, sentData];
- var returnedJSON;
- var url;
- if (this.dev_env == true){
- url = this.devPHPfolderURL;
- }
- else{
- url = this.prodPHPfolderURL;
- }
- //url = this.testURL;
- // let headers = new Headers();
- // headers.append('Content-Type', 'text/plain');
- return this.http.post(url, sentArray)
- .subscribe(
- result => returnedJSON = JSON.stringify(result),
- () => console.log("Failed..."),
- () => console.log("Completed: " + returnedJSON)
- );
- }
- $myServer = "SERVER"; //Actual variable answers were changed for this post.
- $myUser = "USER";
- $myPass = "PASS";
- $myDB = "DATABASE";
- // connection to the database
- $connection = odbc_connect("Driver={SQL Server};Server=$myServer;Database=$myDB;", $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer");
- $result = odbc_prepare($connection, $query);
- odbc_execute($result)or die(odbc_error($connection));
- odbc_close($connection);
- odbc_fetch_array($result);
- header('Access-Control-Allow-Origin: *');
- header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
- header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
- while ($info = odbc_fetch_array($result)) {
- $total[] = $info;
- }
- echo json_encode(odbc_fetch_array($total); //To send to JavaScript
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement