Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Error: parsererror - SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON da

SiberiaAug 1 2014 — edited Aug 1 2014

Hi Apex guys.

I have created an On Demand Ajax Process, called "FDowmload", where i have the next simple file generation script:

begin

-- Set the MIME type

owa_util.mime_header( 'application/octet', FALSE );

-- Set the name of the file

htp.p('Content-Disposition: attachment; filename="emp.csv"');

-- Close the HTTP Header

owa_util.http_header_close;

-- Loop through all rows in EMP

for x in (select e.ename, e.empno, d.dname

from emp e, dept d where e.deptno = d.deptno)

loop

-- Print out a portion of a row,

-- separated by commas and ended by a CR

htp.prn(x.ename ||','|| x.empno ||','||

         x.dname || chr(13));

end loop;

-- Send an error code so that the

-- rest of the HTML does not render

htmldb_application.g_unrecoverable_error := true;

end;

and i am calling it from a javascript in a HTML Region:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>

    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">

    <title>File Download</title>

    <script type="text/javascript">

$(function () {

  $("#alert_id").click(

     function()

      {

        if (confirm('Continue ?'))

         {

           apex.server.process("FDowmload", {async: false});

         }

        else

         {

           alert('Canceled!');

         }

      }

    );

});

    </script>

</head>

<body>

    <p align="center" style="clear: both;">

       <a><href="#" class="myButton" id="alert_id">Process</a>

    </p>

</body>

</html>

But i am facing the next error: Error: parsererror - SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

if i change FDowmload process  from On Demand Ajax Process TO On Load - Before Header, then the file generates correctly as soon as the page load, so the error is in my javascript, but i need to call it from a javascript. 

Any  workarround ?

thanks in Advance

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 29 2014
Added on Aug 1 2014
2 comments
4,990 views