Asked  7 Months ago    Answers:  5   Viewed   32 times

I want to make a form that will use jquery to submit a list of keyword to a php file, this file could take a lot of time to load depending on the size of the keywords list.

What I want to do is to load the php response into a div or container in real time without using iframes.

All the ajax request I know have to wait until the request has finished before having access to the response, I need to get access to that response even when it hasn't finished so I can update the progress in real time.

 Answers

25

Indeed there is a way. With plain old xmlhttpobjects I monitored the readyState. Ready state 4 means the request has ended. Ready state 3 means I can get some of the output and wait for more:

request.onreadystatechange=function()
{
    switch(request.readyState)
    {
        case 4:
            console.log("all good things come to an end");
        break;
        case 3:
            console.log("o, hai!" + request.responseText);
        break;
    }
}

I believe you can achieve the same using jQuery: jQuery: Is req.readyState == 3 possible?

Wednesday, March 31, 2021
 
MassiveAttack
answered 7 Months ago
23

contentType option to false is used for multipart/form-data forms that pass files.

When one sets the contentType option to false, it forces jQuery not to add a Content-Type header, otherwise, the boundary string will be missing from it. Also, when submitting files via multipart/form-data, one must leave the processData flag set to false, otherwise, jQuery will try to convert your FormData into a string, which will fail.


To try and fix your issue:

Use jQuery's .serialize() method which creates a text string in standard URL-encoded notation.

You need to pass un-encoded data when using contentType: false.

Try using new FormData instead of .serialize():

  var formData = new FormData($(this)[0]);

See for yourself the difference of how your formData is passed to your php page by using console.log().

  var formData = new FormData($(this)[0]);
  console.log(formData);

  var formDataSerialized = $(this).serialize();
  console.log(formDataSerialized);
Wednesday, March 31, 2021
 
o_flyer
answered 7 Months ago
62

You seem to want regular json communication (dataType is "json" instead of "jsonp" and server_list.php sends json), but you're setting jsonp options. Remove the jsonp and jsonpcallback lines. Setting jsonp to false does not mean you disable it!

When these two lines are commented out, everything seems to work fine.

Saturday, May 29, 2021
 
khaverim
answered 5 Months ago
78
p = subprocess.Popen([sys.executable, '/path/to/script.py'], 
                                    stdout=subprocess.PIPE, 
                                    stderr=subprocess.STDOUT)

That will start the subprocess in background. Your script will keep running normally.

Read the documentation here.

Thursday, June 10, 2021
 
scessor
answered 5 Months ago
60

You are reading synchronously on the main thread, therefore the UI is not updated until the function returns to the main loop.

There are (at least) two possible approaches to solve the problem:

  • Do the reading from the pipe on a background thread (e.g. by dispatching it to a background queue – but don't forget to dispatch the UI updates to the main thread again).
  • Use notifications to read asynchronously from the pipe (see Real time NSTask output to NSTextView with Swift for an example).
Friday, September 10, 2021
 
stbamb
answered 1 Month ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share