JavaScript CORS is not working with ionic cors not working with https,cors not working with localhost,

I am trying to send a json to a php script on a server and even though I have included header in php script to have CORS the console throws error

error message

XMLHttpRequest cannot load http://www.awesomegag.0fees.us/updata.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access. The response had HTTP status code 403.

my code :

php

<?php 
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Content-Type: application/json; charset=UTF-8");
if (isset($_SERVER['HTTP_ORIGIN'])) {
    header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Max-Age: 86400');    // cache for 1 day
}

// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {

    if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
        header("Access-Control-Allow-Methods: GET, POST, OPTIONS");         

    if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
        header("Access-Control-Allow-Headers:            {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");

    exit(0);
}
echo"hello";
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
?>

My app.js

.controller('datactr',   ['$scope','$http','ApiEndpoint',function($scope,$http,ApiEndpoint) {
$scope.submit=function(){
          console.log("step1");

    $http({
      method:'POST',
      url:'http://www.awesomegag.0fees.us/updata.php',
      data:{
        'name':$scope.name
      }

    }).success(function(data,status,header,config){
      console.log("step2");
      console.log(data);
    })
 });

I tried to make it work using proxy method by making path /api and proxyUrl to updata.php address in ionic.project and then replace url in http service to /api. I get a 500 internal server error.

Can anyone help ?

Update: I have moved to a different server where everything works fine.I guess it is some problem with the server but have no idea how to fix it.

Answer:1

I am new to ExtJs. I have created a twitter widget on twitter. It just works fine on simple html page. As twitter says you just need to include <a class="twitter-timeline" href="https://twitter....

I am new to ExtJs. I have created a twitter widget on twitter. It just works fine on simple html page. As twitter says you just need to include <a class="twitter-timeline" href="https://twitter....

  1. embed twitter widget into website

How do I parse this to int? "'10'" Thanks.

How do I parse this to int? "'10'" Thanks.

  1. convert double quotes to html
  2. convert double quotes to ascii
  3. convert double quotes javascript
  4. vscode convert double quotes to single
  5. php convert double quotes to single
  6. json convert double quotes
  7. php convert double quotes
  8. python convert double quotes
  9. java convert double quotes
  10. bash convert double quote

I'm using phantomjs for taking screenshots of several webpages. To get a screenshot image i have used the following code. var page = require('webpage').create(); page.viewportSize = { width: 1200,...

I'm using phantomjs for taking screenshots of several webpages. To get a screenshot image i have used the following code. var page = require('webpage').create(); page.viewportSize = { width: 1200,...

I am trying to load webviews in a view pager. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = null; ...

I am trying to load webviews in a view pager. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = null; ...