0

I tried to Get the variables from My form. My script is:

$(function() {
    var title = $ ( "#title" ),
      message= $( "#message" ),
      category = $( "#category" ),

      allFields = $( [] ).add( title ).add( message ).add( category ),
      tips = $( ".validateTips" );

    function updateTips( t ) {
      tips
        .text( t )
        .addClass( "ui-state-highlight" );
      setTimeout(function() {
        tips.removeClass( "ui-state-highlight", 1500 );
      }, 500 );
    }

    function checkLength( o, n, min, max ) {
      if ( o.val().length > max || o.val().length < min ) {
        o.addClass( "ui-state-error" );
        updateTips( "Length of " + n + " must be between " +
          min + " and " + max + "." );
        return false;
      } else {
        return true;
      }
    }

    function checkRegexp( o, regexp, n ) {
      if ( !( regexp.test( o.val() ) ) ) {
        o.addClass( "error" );
        updateTips( n );
        return false;
      } else {
        return true;
      }
    }

    $( "#dialog-form" ).dialog({
      autoOpen: false,
      height: 600,
      width: 550,
      modal: true,
      buttons: {
        "Create an account": function() {
          var bValid = true;
          allFields.removeClass( "error" );

          bValid = bValid && checkLength( title, "Title", 3, 16 );

          bValid = bValid && checkLength( message, "message", 5, 360 );
          bValid = bValid && checkLength( category, "category", 5, 16 );

          bValid = bValid && checkRegexp( title, /^[a-z]([0-9a-z_])+$/i, "Title may consist of a-z, 0-9, underscores, begin with a letter." );
          bValid = bValid && checkRegexp( message, /^[a-z]([0-9a-z_])+$/i, "Message may consist of a-z, 0-9, underscores, begin with a letter." );
          bValid = bValid && checkRegexp( category, /^[a-z]([0-9a-z_])+$/i, "Category may consist of a-z, 0-9, underscores, begin with a letter." );




          if ( bValid ) {
            $.post("upDate.php",{title: tilte.val(), message: message.val(), categorie: category.val()});


           $( "#users-contain" ).append('<div class="bubble-list">    <div class="bubble clearfix"> <img src="./img.php?message=MY PROFIL PIC" title="'+ title.val()+'"> <div class="bubble-content"> <div class="point"></div><p>' + message.val() +'</p><ul class="tags"><li><a href="#">'+ category.val() +'</a></li></ul></div></div></div>' );


                        $( this ).dialog( "close" );

          }
        },
        Cancel: function() {
          $( this ).dialog( "close" );
        }
      },
      close: function() {
        allFields.val( "" ).removeClass( "ui-state-error" );
      }
    });

    $( "#create-user" )
      .button()
      .click(function() {
        $( "#dialog-form" ).dialog( "open" );
      });
  });

I tied to make some alert to see the callback but, also don't work. I use the last version of jQuery UI, I don't know what is my problem there.

4

1 回答 1

1

1号

为什么不使用.serialize()进行发布?这对你来说真的很简单,

2号

当您传递变量时,您的代码中有错误(错字),

 $.post("upDate.php",{title: tilte.val(),... //tilte??

应该

 $.post("upDate.php",{title: title.val(),....
于 2013-08-04T05:44:45.430 回答