1

I have been on this for a while now. For some reason my Password field does not arrive to my editaccount.php via ajax. Please confirm the Jquery is Correctly setup to add the pass to the variables to send if pass is NOT disabled. I would like to confirm ALL other fields DO SEND.

No one seems to know the fix to this. If check this if statement using alert() in console then yes it should work. But the pass never gets placed into the object myData. Why? How can i fix this? I know the password select is correct. if i remove the if statement then the pass is delievered.

JQuery:

$(document).on('submit', '#editaccount', function(event) {
event.preventDefault();

myData = {
        contactname: $('input[name=contactname]').val(),
        business: $('input[name=business]').val(),
        email: $('input[name=email]').val(),
        code: $('input[name=code]').val(),
        phone: $('input[name=phone]').val(),
        priceband: $('input[name=priceband]').val(),
        address: $('input[name=address]').val(),
        active: $('input[name=active]').val(),
        mon: $('input[name=mon]').val(),
        tue: $('input[name=tue]').val(),
        wed: $('input[name=wed]').val(),
        thu: $('input[name=thu]').val(),
        fri: $('input[name=fri]').val(),
        sat: $('input[name=sat]').val(),
        sund: $('input[name=sund]').val(),
        adminname: $('input[name=adminname]').val(),
        accountid: $('input[name=accountid]').val(),
        isadmin: $('input[name=isadmin]').val(),

};

var isDisabled = $('input[name=pass]').is(':disabled');

if (isDisabled == false) {
        myData.pass = $('input[name=pass]').val();
}

$.ajax({
    url: 'php/editaccount.php',
    type: "POST",
    data: myData,
    success: function(data) {

        if ($('input[name=isadmin]').val() == 1) {
            $('input[name=accountsearch]').val($('input[name=email]').val());
            $('input[name=accountsearch]').submit();
        } else {
            $('input[name=accountsearch]').val($('input[name=business]').val());
            $('input[name=accountsearch]').submit();
        }

        alert(data);
    }
});
});
  • When you debug this, is `myData.pass` being set? Is it included in the HTTP request that the browser is sending? Also, what is this supposed to be doing: `$_POST['name=pass']` – David Jun 07 '15 at 13:41
  • How can i check this? –  Jun 07 '15 at 13:45
  • Browser debugging tools. Firebug, Chrome developer tools, etc. They have debuggers you can use to step through the code as it executes, and they have tools to monitor HTTP requests so you can examine the contents of those requests. – David Jun 07 '15 at 13:46
  • I believe its directly related to: var isDisabled = $('input[name=pass]').is(':disabled'); if (isDisabled == false) { myData.pass = $('input[name=pass]').val(); } –  Jun 07 '15 at 13:57

2 Answers2

0

I think you need to use .push() if disabled so you can read myData.pass

var isDisabled = $('input[name=pass]').is(':disabled');

if (isDisabled == false) {
        myData.push('pass : '+$('input[name=pass]').val());
        alert(myData.pass);
}

after that you will need Send array with Ajax to PHP script

Community
  • 1
  • 1
Mohamed-Yousef
  • 23,946
  • 3
  • 19
  • 28
0

the problem with this code is that you online create the myData.pass variable if the isDisabled = false but else the object never create the pass variable to the object, here the solucion :

var isDisabled = $('input[name=pass]').is(':disabled');

if (isDisabled == false) {
    myData.pass = $('input[name=pass]').val();
}eles{
//here you que asign the value of pass to empty o to null
myData.pass = "";
}

and here is the the complete code :

    $(document).on('submit', '#editaccount', function(event) {
    event.preventDefault();

    myData = {
            contactname: $('input[name=contactname]').val(),
            business: $('input[name=business]').val(),
            email: $('input[name=email]').val(),
            code: $('input[name=code]').val(),
            phone: $('input[name=phone]').val(),
            priceband: $('input[name=priceband]').val(),
            address: $('input[name=address]').val(),
            active: $('input[name=active]').val(),
            mon: $('input[name=mon]').val(),
            tue: $('input[name=tue]').val(),
            wed: $('input[name=wed]').val(),
            thu: $('input[name=thu]').val(),
            fri: $('input[name=fri]').val(),
            sat: $('input[name=sat]').val(),
            sund: $('input[name=sund]').val(),
            adminname: $('input[name=adminname]').val(),
            accountid: $('input[name=accountid]').val(),
            isadmin: $('input[name=isadmin]').val(),

    };

    var isDisabled = $('input[name=pass]').is(':disabled');

if (isDisabled == false) {
    myData.pass = $('input[name=pass]').val();
}eles{
//here you can asign the value of pass to empty o to null
myData.pass = "";
}

    $.ajax({
        url: 'php/editaccount.php',
        type: "POST",
        data: myData,
        success: function(data) {

            if ($('input[name=isadmin]').val() == 1) {
                $('input[name=accountsearch]').val($('input[name=email]').val());
                $('input[name=accountsearch]').submit();
            } else {
                $('input[name=accountsearch]').val($('input[name=business]').val());
                $('input[name=accountsearch]').submit();
            }

            alert(data);
        }
    });
    });
Fermin Perdomo
  • 411
  • 4
  • 11