Create a hyperlink (or button) that executes a python script and then redirects when script completes

前端 未结 4 1818
死守一世寂寞
死守一世寂寞 2020-12-14 12:26

Alright, I managed to get it working how I want (although some/most might disagree with the method). I used Flask as recommended below. The part that might be considered \"w

4条回答
  •  清歌不尽
    2020-12-14 13:03

    What you want is possible, but it's really about 3 problems.

    The first question is, how do you create a new file from PHP. I can't really answer this one. What you need to do, probably depends on what kind of file you're trying to create and why.

    The second question is, how do you let the user know this is happening, and the third is how do you redirect to the new page.

    Personally, I think the shortest route to victory, is probably to have your client-side javascript make an AJAX request to the server page or CGI module that creates your new content.

    1. On button click, make an ajax request to the PHP page that generates your new content page.
    2. Present your busy indicator.
    3. Have the requested page return the URL of the new page as its content.
    4. When the request completes redirect to the returned URL via javascript.

    As someone new to web development, the easiest thing to do might be to look into jQuery and it's AJAX functionality. The wrappers there make it pretty easy to do the above. Of course you can do the same with any of the other major javascript frameworks or straight javascript as well.

    For reference:

    • http://api.jquery.com/jQuery.ajax/
    • http://www.tizag.com/phpT/filecreate.php

提交回复
热议问题