SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 38 of 38
  1. #26
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,060
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Cool!

    Now we've got to start putting bits back in until we find out what is causing the error.

    Change this:

    PHP Code:
    if ($status == 1) {  
      echo 
    "All Good"

    to this:

    PHP Code:
    if ($status == 1) {  
      require_once(
    "categoryfinder.php");  
      
    $categoryFinder = new CategoryFinder;  
      
    $category $categoryFinder -> getCategory();  
                      
      
    $response['validation'] = "pass";  
      
    $response['message'] = "Thanks for joining the e-mail list, <b>" $name "</b>, under the e-mail address, <b>" $confirmEmail "</b>.";
      
      echo 
    json_encode($response);

    What do you see on the console?

  2. #27
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    632
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I don't think we have gotten down to a successful AJAX call. I still see the same error message that is being thrown by the error block of that AJAX call.

    What I am seeing now in the console is:
    All Good{"validation":"pass","message":"Thanks for joining the e-mail list, <b>Tyler<\/b>, under the e-mail address, <b>etidd88@ymail.com<\/b>.","database":" "}

  3. #28
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,060
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by etidd View Post
    I don't think we have gotten down to a successful AJAX call.
    We have, as before you wrote:

    Quote Originally Posted by etidd View Post
    If I put a valid submission on everything, I get the alert message of 'error'. When using a unique e-mail not already in the database, the user's data is written (success) but the AJAX call is an overall failure
    This is also backed up by the fact that we are seeing all of this in the success callback.

    Just to be sure however, can you remove the error callback from the JavaScript, like so:

    Code JavaScript:
    $.ajax({
      type: "POST",
      dataType: 'json',
      cache: false,
      url: "Scripts/confirmform.php",
      data: { 
      origEmail: origEmail,
      confirmEmail: confirmEmail,
      name: name,
      age: age,
      gender: gender,
      country: country,
      catcher: catcher,
      addition: addition,
      mathAnswer: mathAnswer,
      submissionTime: submissionTime 
      },
      success: function(data) {
        console.log(data);
      }
    });


    and confirm that you are still seeing the same results.

  4. #29
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    632
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I really don't think it's working properly, seeing as I still have a call to the other function that shows/hides the forms, displays a success message in the #submitstatus div, and fades out. I'm seeing none of that anymore, even with a valid submit.

    Code JavaScript:
    			  success: function(data) {
    				alert("success");
    				console.log(data);
    				testSecondResults(data);
    			  },
    To add to that, I'm not seeing an alert message saying 'success'.

    I did what you said, anyhow, and removed the error callback and I am seeing the same results:
    All Good{"validation":"pass","message":"Thanks for joining the e-mail list, <b>Tyler<\/b>, under the e-mail address, <b>etidd88@ymail.com<\/b>.","database":" "}

  5. #30
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,060
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by etidd View Post
    I really don't think it's working properly, seeing as I still have a call to the other function that shows/hides the forms, displays a success message in the #submitstatus div, and fades out. I'm seeing none of that anymore, even with a valid submit.


    We first have to work out what's going wrong in the PHP code as, as we established previously, upon a valid form submission, it cannot encode the string it is handed as JSON.
    Once we solve that, the rest should follow quite easily.
    At least that's the theory ...

    Quote Originally Posted by etidd View Post
    I did what you said, anyhow, and removed the error callback and I am seeing the same results:
    OK, try changing your PHP code to this and let me know what gets logged to the console.

    PHP Code:
    if ($status == 1) {  
      require_once(
    "categoryfinder.php");  
      
    $categoryFinder = new CategoryFinder;  
      
    $category $categoryFinder -> getCategory();  
            
      
    $response['validation'] = "pass";  
      
    $response['message'] = "Thanks for joining the e-mail list, <b>" $name "</b>, under the e-mail address, <b>" $confirmEmail "</b>.";  
                    
      require_once(
    'databasewriter.php');  
      
    $dbWriter = new DatabaseWriter;  
      
    $dbCode $dbWriter -> writeUserToDatabase($confirmEmail$name$ageRange$gender$country$category);  
      
      if (
    $dbCode == 1) {  
        
    $response['database'] = "pass";  
      } else {  
        
    $response['database'] = "fail";  
        
    $response['validation'] = "fail";  
      }  
      
      echo 
    json_encode($response);  


  6. #31
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    632
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The console says:
    All Good{"validation":"fail","message":"Thanks for joining the e-mail list, <b>Tyler<\/b>, under the e-mail address, <b>etidd88@ymail.com<\/b>.","database":"fail"}
    I'm sure the database writing failed because I already have wrote that e-mail address in there before. That doesn't matter in this case, though. I know the database script is fine.

  7. #32
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,060
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    It shouldn't say "All Good", as I removed that from the PHP a few posts back.

    Nonetheless, we're a step forward, so let's add the final bit back in:

    PHP Code:
    if ($status == 1) {  
      require_once(
    "categoryfinder.php");  
      
    $categoryFinder = new CategoryFinder;  
      
    $category $categoryFinder -> getCategory();  
            
      
    $response['validation'] = "pass";  
      
    $response['message'] = "Thanks for joining the e-mail list, <b>" $name "</b>, under the e-mail address, <b>" $confirmEmail "</b>.";  
                    
      require_once(
    'databasewriter.php');  
      
    $dbWriter = new DatabaseWriter;  
      
    $dbCode $dbWriter -> writeUserToDatabase($confirmEmail$name$ageRange$gender$country$category);  
      
      if (
    $dbCode == 1) {  
        
    $response['database'] = "pass";  
      } else {  
        
    $response['database'] = "fail";  
        
    $response['validation'] = "fail";  
      }  
      
      if (
    $dbCode == 2) {  
        
    $response['message'] = "Server error. Please try again later.";  
      } elseif (
    $dbCode == 3) {  
        
    $response['message'] = "That e-mail address already exists.";  
      }  
      
      echo 
    json_encode($response);  

    What does that give you on the console?

  8. #33
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    632
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Talking Success?!?!

    Well, I'll be darned! It worked!

    The console says:
    {"validation":"fail","message":"That e-mail address already exists.","database":"fail"}
    Not only that, but the ajax request gave me the success message, and the message was posted to the <p> element with the i.d. of #errormessage just like I want it to.

    How?! I don't know how anything was changed that much. This obviously shows the power of stepping through the code bit by bit. I'm at a loss to explain the fix, however, because I don't know what's really any different than what was originally coded.

  9. #34
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    632
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Ah-ha. The solution is that the extra echo statements I had in the script that said "Database Write Successful" or "Database Write Failure" were causing a problem.

  10. #35
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,060
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Excellent. Well done!

    The only thing I altered about the original PHP code, was that I removed the echo statements, e.g.:

    PHP Code:
    echo 'Database Write Successful'
    This is probably what was causing the error. This is something you can check.

    Edit: You were quicker. Great minds think alike

  11. #36
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,060
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by etidd View Post
    Not only that, but the ajax request gave me the success message, and the message was posted to the <p> element with the i.d. of #errormessage just like I want it to.
    Also, don't get confused with the success and error callbacks.

    If you submit your form with invalid data and the PHP script spits a "validation failed" message back at you, this is still a successful AJAX call.

    The error callback would be more for the case that your PHP script falls over and dies due to a syntax error (or something similar) and that the AJAX call cannot complete successfully.

  12. #37
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    632
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Well, thank you as always, Dave.

    I certainly could not have gotten as far as I have without these forums & the books I have gotten from SitePoint.

    I'm getting so close to completing this project, moving on to the next one, and using this project in internet marketing campaigns.

    I've tried to help people on the forums like this before, but I'm not nearly experienced enough to help people along.

  13. #38
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,060
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    You're welcome.

    Quote Originally Posted by etidd View Post
    I've tried to help people on the forums like this before, but I'm not nearly experienced enough to help people along.
    Don't think that!
    Just hang around the place and sooner or later you'll see a question where you think "Hey, I can answer that".
    Then you'll see another, and another, and so on ...
    Don't underestimate your own knowledge.

    Also, there are loads of less technical forums here, such as the Community Center or Content.



Tags for this Thread

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
  •