Google App Engine serving jQuery and Python files returns 2 identical files instead of 1

I am running Flask on GAE with a backend with the Google engine. I submit the form to my website, submit it to the backend, the backend returns an xml file, and I would like to serve this XML file. However, I have a problem serving my file.

This is the only way to find out how to maintain my file, it works, but it returns 2 identical files in the browser instead of one, what am I doing wrong?

In jQuery interface:

$.get('submit',
        dat,
        function(data, status, request) {
            if (status = 'success'){
                console.log(status);
               $("body").append("<iframe src='" + request.getResponseHeader('redirect')+ "' style='display: none;' ></iframe>");
            }
            else 
                alert("There is an exception on server side while submitting the response!");

        }, 
        'xml'); 

In the Python interface:

@app.route("/submit", methods=["GET"] )
def submit():
... do some stuff to get the data and url packaged...
  headers = {'content-type': 'application/json', 'charset':'UTF-8'}
  r = requests.post(url, data=json.dumps(jsonstring), headers=headers)
  response = make_response(r.text)
  response.headers["Content-Type"] = 'application/xml'
  response.headers.add("redirect", request.url)
  response.headers["Content-Disposition"] = 'attachment; filename="exportChecklists.xml"'

  return response

Basically, I added the redirect URL, which was my request URL, so when the file was ready, I just created a hidden iFrame that scans modern browsers and asks for downloads.

How can I change this to get only 1 file instead of 2?

.

UPDATE

. ( , XML ).

var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "POST", "/submit", false );
xmlHttp.setRequestHeader("Content-type", "application/json");
xmlHttp.send( JSON.stringify(dat ));
return xmlHttp.responseText;

Response Headers:    
Cache-Control:no-cache
content-disposition:attachment; filename="exportChecklists.xml"
Content-Length:76
content-type:application/xml
Date:Fri, 27 Dec 2013 22:59:27 GMT
Expires:Fri, 01 Jan 1990 00:00:00 GMT
Server:Development/2.0

# 2

, , . , , 1 , jQuery. - , .

+4
1

, , , - :

:

, :

var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "POST", "/submit", false );
xmlHttp.setRequestHeader("Content-type", "application/json");
xmlHttp.send( JSON.stringify(dat ));
return xmlHttp.responseText;

1:

6 return xmlHttp.responseText; , -, .. XML, .

1:

, , XML.


2:

content-disposition:attachment; filename="exportChecklists.xml"

XML .

2:

XML.


:

, , , , , ...


, AlexIIP :

jQuery:

$.get('submit',
    dat,
    function (data, status, request) {
        if (status = 'success') {
            console.log(status);
            $("body").append("<iframe src='" + request.getResponseHeader('redirect') + "' style='display: none;' ></iframe>");
        } else alert("There is an exception on server side while submitting the response!");    
    },
    'xml');

, :

$("body").append("<iframe src='" + request.getResponseHeader('redirect') + "' style='display: none;' ></iframe>");

request.getResponseHeader('redirect') iframe, , XML, XML, XML iframe content-disposition:attachment; filename="exportChecklists.xml" , . (, iframe doc, , 2).

, JavaScript, , , :

XML, ( "" ) XML-...

, JavaScript, return xmlHttp.responseText;, (HTML), , URL- XML. , XML, :

return xmlHttp.responseText;

:

return xmlHttp.getResponseHeader('redirect');

XML , , ...

+3

All Articles