-1

so iam posting a form using jquery and ajax it works fine but i want to update a div after that finishes so i used .ready but it does not work it just loads the older version i have to press again in order for it to work so any suggestions and if there is something iam doing wrong and i should fix please mention it

  function EditDeal(Item_id)
    {
        var Url_ = "<?php echo $_SERVER['PHP_SELF'].'?id='?>"+Item_id;
        $("#addItem").submit(function(param)
    {

        var formObj = $(this);
        var formURL = formObj.attr("action");
        var formData = new FormData(this);
        $.ajax({
            url: Url_,
            type: 'POST',
            data:  formData,
            mimeType:"multipart/form-data",
            contentType: false,
            cache: false,
            processData:false
        });
        param.preventDefault();
    });

    $("#addItem").submit().ready(function(){
            $('#show').css('opacity', 0).load("DealsConfigure.php #show", function() {
            $(this).animate({ opacity: 1 }, 'fast');});

            });
    }
Scary Wombat
  • 44,617
  • 6
  • 35
  • 64
Amgad Serry
  • 1,595
  • 2
  • 12
  • 20

1 Answers1

0

The ajax call is asynchronous, so you will need to use the success callback block

E.g.

$.ajax({
        url: Url_,
        type: 'POST',
        data:  formData,
        mimeType:"multipart/form-data",
        contentType: false,
        cache: false,
        processData:false,
        success: function (data) {
            // do whatever you want
        }
    });
Scary Wombat
  • 44,617
  • 6
  • 35
  • 64
  • okay this works but there is a problem every time i use this i submits 1 more time for example at 2nd press it submits the form twice so any idea what is that ? – Amgad Serry Dec 27 '13 at 01:55
  • After subnitting once, look at the code that is being reloaded into `#show` – Scary Wombat Dec 27 '13 at 01:57