www.webdeveloper.com
Results 1 to 6 of 6

Thread: Newsletter Builder

  1. #1
    Join Date
    Dec 2011
    Posts
    163

    Exclamation Newsletter Builder

    I am currently in the process of making a Newsletter Builder, the current code is as follows...

    (This is my first attempt at jQuery ajax)

    HTML
    HTML Code:
    <div id="buildBox"></div>
    ...
    <div id="buildNow">Build</div>
    PHP (newsletter_build_ajax.php)
    PHP Code:
    <?php 
    if($_POST['submit']){
        
    $buildBox $_POST['build'];
        
    $file "/home/newsletter/current.html";
        
    $fp fopen($file'w');
        
    fwrite($fp,$buildBox);
        if(
    fclose($fp)){
            echo 
    "ok";
        } else {
            echo 
    "error";
        }
    }

    ?>
    jQuery
    HTML Code:
    // AJAX BUILD
    	var $buildNow = $("#buildNow");
    	$buildNow.on("click", function(){
    		$buildNow.css("border-color", "rgba(0,204,255,1)");
    		$buildNow.text("Building...");
    		$.ajax({
    			url:"_includes/newsletter_build_ajax.php",
    			type: 'POST',
    			data: { 'build': $buildBox.html() , 'submit' :''},
    			dataType:"html",
    			success: function(data, status){
    				if(data == "ok"){
    					$buildNow.css("border-color", "rgba(0,255,0,1)");
    					$buildNow.text("Built!");
    					
    				}
    			},
    			error: function(xhr, desc, err){
    				console.log(xhr);
    				console.log("Details: " + desc + "\nError: " + err);
    				$buildNow.css("border-color", "rgba(255,0,0,1)");
    				$buildNow.text("Build Failed");
    			}
    		}); // END AJAX
    	});
    I just simply want to write the contents of #buildBox to the current.html file, when the Build div is clicked.

    But my AJAX simply won't execute, Just changes text to "Building..." and stays.

  2. #2
    Join Date
    Dec 2011
    Posts
    163
    Nothing?

  3. #3
    Your first attempt was too good dear, keep it up!

  4. #4
    Join Date
    Dec 2011
    Posts
    163
    Attempt, yes, but it does not work, could it be that the POST superglobal has a character limit? I mean, I am passing a lot of stuff through it.

  5. #5
    Join Date
    May 2014
    Posts
    1,017
    data: { 'build': $buildBox.html() , 'submit' :''}

    if($_POST['submit']){

    Do we see the problem here???

    You're sending 'submit' as empty, empty is the same as false... so your very first IF statement is gonna fail to be true. Did you mean to use isset?
    Java is to JavaScript as Ham is to Hamburger.

  6. #6
    Join Date
    Dec 2011
    Posts
    163
    I took the submit off both the ajax request and the php processing form, still nothing.

Thread Information

Users Browsing this Thread

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

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