javascript - Calling to to another page with AJAX while showing loading image -


i have php gets parameters post , @ end of process redirects user page.

because whole process can take 6 seconds, wanted add loading gif. i've created page shows image , calls first page using ajax.

no matter i've tried, not able make whole process work. @ end xmlhttprequest cannot load error - no 'access-control-allow-origin' header present on requested resource. origin 'http://localhost:8888' therefore not allowed access.

this code of page calls php process file:

<?php  function generatedata(){     global $dpost;     foreach ($_post $key => $value){         $dpost .= ',' . $key . ':"' .  $value . '"';     }     $dpost .= ',resulttype:"pre"';     $dpost = '{' . substr($dpost, 1) . '}'; } ?>  <html> <head>     <link rel="stylesheet" type="text/css" href="default.css">     <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script> </head> <body>     <?php generatedata(); ?>     <script type="text/javascript" >         console.log('1');         var text='';         $.ajax({             url: 'f-api.php',             type: 'post',             headers: {  'access-control-allow-origin' : '*'},             crossdomain : true,             content_type: 'application/json',             datatype: 'json',             data: <?php global $dpost; echo $dpost; ?>,             success: function(data) {                 console.log('ok')                 alert(text);                 $('.my_update_panel').html(data);                 $('#loading_spinner').hide();             },            error: function(data) {                console.log('error : ' + data);             },             beforesend: function(xhr) {                 console.log('before');                 xhr.setrequestheader('access-control-allow-origin', '*');             }         });     </script>     <div>         <img src="img/loading-ls.gif">     </div> </body> </html> 

this code inside process php file redirect end url :

        logger($lfn, 'debug', 'redirecting ' . $url, $email);     header('access-control-allow-origin: *;');     header("location: " . $url);     die(); 

any idea how fix this? or maybe accomplish i'm looking for?

no 'access-control-allow-origin' header present on requested resource

this issue says it's not allowing incoming requests page, , can fixed adding following .htaccess file:

header add access-control-allow-origin "*" header add access-control-allow-headers "origin, x-requested-with, content-type" header add access-control-allow-methods "put, get, post, delete, options" 

alternatively, .php file you're sending data to:

header("access-control-allow-origin: *"); header("access-control-allow-methods: put, get, post, delete, options"); header("access-control-allow-headers: *"); 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -