Results 1 to 2 of 2

Thread: jQuery Mobile with AJAX - Flip a toggle-switch and change a field in a MySQL Database

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Seattle, WA

    Exclamation jQuery Mobile with AJAX - Flip a toggle-switch and change a field in a MySQL Database

    Ok, so I have a toggle-switch with the ID "agOn" and then I have a function to make a div show/hide when it's flipped... but I also want to change "agStatus" in my database to 1 or 0 when the toggle is flipped... so when the div is hidden, the database updates with agStatus = 0 and when the div is visible, the agStatus will be updated with agStatus = 1.

    $('#agOn').change(function() {
        var myswitch = $(this);
        var show     = myswitch[0].selectedIndex == 1 ? true:false;
    		type: "POST", 
    		url: serviceURL + "submitdata.php", 
    		data: 'type='+'agentInfo'+'id='+'30'+'status='+agOn , 
    		cache: false, 
    		success: function(response){
    			//alert("Record successfully updated");
    I've tested it and checked the database, but it's not getting updated... the part to toggle the div visibility is working fine, though.

    Any help would be greatly appreciated. Thanks!

  2. #2
    Join Date
    Oct 2010
    Versailles, France
    This may be zero, which causes an error with an empty($_POST["agOn"]) ? Then an isset() would be better ?

    In any case, check the POST variables (with a line foreach ($ POST as $ k => $ v) echo "$k => $v<br>";) in the file submitdata.php and an alert(response.responseText) in the callback function)
    Last edited by 007Julien; 11-27-2012 at 06:28 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles