开发者

writing php serverside code for image processing using ajax on frontend. PHP

开发者 https://www.devze.com 2023-03-28 22:42 出处:网络
I have some script that takes a form and sends it to php using jquery ajaxSubmit. Server side must copy image from one location to another.

I have some script that takes a form and sends it to php using jquery ajaxSubmit.

Server side must copy image from one location to another. using this code copy($img_dir_file,$mini_dir_file); is ok if u have few images.

But if u have let's say 20+ images php works slowly, and responds to ajax before finishing it's job. Thus Ajax changes content to blank page , cause result is not ready.

If you refresh page a bit later, everything is ok cause php finishes his work.

So please tell me what should I do with this problem ?

script is something like this

$('#save_edited_article').liv开发者_高级运维e('click',function(){
$('#edited_article_form').ajaxSubmit({
success: function(responseimage){
$('#main_content').html(responseimage) } }); });


You could use a Promise which will inform the browser when the job is complete.

Check out the jqXHR Object as part of Ajax on JQuery - you could then change your main content when the jqxhr object ( which works as a Promise) is complete :

jqxhr.done(function(){ $('#main_content').html(responseimage); });


Edit

An example using your code could be:

$("#edited_article_form").submit(function() {
    var jqxhr = $.post(
        "foo.php",
        $("#edited_article_form").serialize()
    );
    jqxhr.fail(function(){ alert("fail") });
    jqxhr.done(function(responseimage){ $('#main_content').html(responseimage) });
});

Disclaimer : This was written on the fly and may not compile. It is for example purposes only


Have the AJAX call check to see if it's complete, if it's not, keep polling every few seconds until it's ready.


Updated jQuery and ajaxSubmit plugin and everything works nice.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号