SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    (jquery) json sending data

    I have this ajax that sends some form data to the server. within the ajax I have a getJSON. How can I send that same form data in the getJSON?

    Code JavaScript:
    <script>
    function personal(){
           $.ajax({
               type: "POST",
               url: "settings_personal.php",
               data:     "first_name=" + document.getElementById("first_name").value + "&last_name=" + document.getElementById("last_name").value + "&email=" + document.getElementById("email").value,
               dataType: "json",
               success:  function (html) {
     
                   var error = html.error;
                   if (html !== "") {
                       $('.save-button').replaceWith('<div class="save-button"><input onclick="personal()" name="update_profile" type="button" value="Error :(" class="btn btn-danger btn-large"/>&nbsp;<input name="reset" type="submit" value="Reset" class="btn btn-inverse btn-large"/>')
                   }
     
                   if (html == "") {
                       $('.save-button').replaceWith('<div class="save-button"><input onclick="personal()" name="update_profile" type="button" value="Saved" class="btn btn-success btn-large"/>&nbsp;<input name="reset" type="submit" value="Reset" class="btn btn-inverse btn-large"/>')
                   }      
     
                   $.getJSON("settings_personal.php", function(result){
                       $.each(result, function(i, field){
                         alert(field);
     
                       });
                     });                  
               }           
           });
    }
    </script>

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Jaynesh View Post
    I have this ajax that sends some form data to the server. within the ajax I have a getJSON. How can I send that same form data in the getJSON?
    By using jQuery's serialize() method
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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