Jump to content

Q695

Members
  • Posts

    783
  • Joined

  • Last visited

Posts posted by Q695

  1. Going from something like:

    $sql_update='';
    $binders='';
    if(isset($_POST['name']) && $_POST['name']!=''){
    $name=$_POST['name'];
    $binders.=",$name";
    
    $sql_update.="`name`=?";
    }
    ...
    if(isset($_POST['phone']) && $_POST['phone']!=''){
    $phone=$_POST['phone'];
    $binders.=",$phone";
    
    $sql_update.="`phone`=?";
    }
    $binders = trim($binders, ',');
    $sql_update = trim($sql_update, ',');
    
    
    if ($sql_update!='' && $binders!='') {
    $sql = "UPDATE ___table___
    SET $sql_update
    WHERE id=$___id___";
    $q = $conn->prepare($sql);
    // $q->execute(array($binders,$___id___));
    
    }

    How would you send it to the PDO function?

     

    I spent the whole day trying to convert it from a mysql statement to a PDO statement, and feel like  :suicide:

  2. When I put the run_modal( href, url_data ) inside the jquery function() it says:
    Uncaught Reference Error: run_modal is not defined

     

    when outside It says:

    Uncaught Error: cannot call methods on dialog prior to initialization; attempted to call method 'open'

     

    when I remove the return false the hyperlink behaves as it always has.

     

    I'm just trying to be able to pass the function variables in through the "old method" to make the function more understandable (maybe I need to see a video on how exactly the jquery variable system works).

     

    vision:

    you have X possible modals that can be triggered you're trying to only trigger 1 modal that will use the variables it receives to run its ajax lookup.

  3. Here's a better approach though, that uses more pure jquery than you are using. It also tremendously simplifies things.

     

     

    <div id='dialog' title='Blog Post Viewer'></div>
     
    //Just use the href, and create a html data attribute to hold the "url_data". Give them all the same class and jQuery will pick it all up using my function which is automatically invoked.
    <a href='?a=a&b=b' data-urldata="data a" class="modalize"> link text a</a>
    <a href='?c=c&d=d' data-urldata="data b" class="modalize"> link text b</a>
     
    $(function() {
        
        //create a click event for all links with class of "modalize"
        $('a.modalize').on('click', function(e) {
            e.preventDefault(); //jQuery equiv for return false for click event
            
            var link = $(this); //the clicked link
            
            //grab the link href
            var href = link.attr('href');
            
            //grab the link urldata
            var urldata = link.data('urldata');
           
            alert('href: ' + href + "\nData: " + urldata);
            
            //now do the ajax, open dialog box, etc
            $( "#dialog" ).dialog({
              autoOpen: false
            });
        });
    });
     

    Example:

    https://jsfiddle.net/tagwgLch/1/

     

    This would work, if I wasn't trying to run a modal instead of an alert for presentation reasons: https://jqueryui.com/dialog/#modal-form

     

    The error I'm getting is: Uncaught Error: cannot call methods on dialog prior to initialization; attempted to call method 'open'

  4. Here's what I'm starting with:

     

    javascript:

    $(function() {
        $( "#dialog" ).dialog({
            autoOpen: false
        });
    });
    
    function run_modal( href, url_data ) {
    //    $("#dialog").dialog("open");
        $( "#dialog" ).dialog( "open" );
        alert(href+"?"+url_data);
    }
    

    PHP:

    echo "
    <div id='dialog' title='Blog Post Viewer'></div>
    ";
    function modalize($link_txt, $href, $url_data){
        //<a href='?$url_data' onmousedown='run_modal()' onclick='return false' >$link_txt</a>
        echo "
    <a href='? $url_data ' onclick='return false' onmousedown=' run_modal ( \" $href \" , \" $url_data \" );'> $link_txt </a>
     ";
    
    
    }
    

    I'm struggling to make the modal popup.

     

    From there I plan to plug in my own generic ajax loader to request the data to be populated in the modal.

  5. I'm struggling to produce results to the screen from the following code:

     

    HTML:

    <script src="http://code.jquery.com/jquery-2.1.4.js"></script>
    <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    
    <script src="../scripts/autocomplete.js"></script>
    
    <div>
        <input type='text' class='search_input' name='search' id='search' placeholder='search' autofocus onkeypress='search_func("http://webfarm.io/subs/homefront/list_articles.php" , "search_output")'>
    
        <div id='search_output' class='search_output'></div>
    </div>
    
    

    Javascript:
     

    function search_func( href , target){
            var search = $("#search").val();
            search = $.trim(search);
    
            if(search){
                $.ajax({
                    method: "POST",
                    url: href ,
                    data: { search: search }
                })
                    .done(function( msg ) {
                        target.innerHTML = msg; // as above, data holds the result of the request, so all the data returned from your results.php file are in this param but please see below;
                        console.log(msg);
                    });
            } else {
                target.innerHTML = '';
            }
    }
    

    What am I doing wrong?

    Why won't it produce the desired results?

    Sorry if I'm looking like a help vamp, but I'm not trying to be.

  6. You shouldn't have to append the data directly to the url - using the 'get' method will handle that for you, as well as JSON encoding the data. However, you do have to give the data to the ajax call.

    $.ajax({
    	type:'get',
    	url:href,
    	beforeSend:function(){
    		$('#target').html("<p>Doing something - please wait.</p>");
    	},
    	data:url_data,
    }).done(function(ajaxObject){
    	var resp = JSON.parse(ajaxObject);
    	if(resp.success == true){
    		$('#target').html("<p>Woot!</p>");
    	}else{
    		$('#target').html('<p>Processing error - system returned false!</p>');
    	}
    }).error(function(){
    	$('#target').html('<p>System error - not processing related!</p>');
    });
    

    Note that there' are both a done() and error() handler attached to this. sucess() will always fire as long as the call itself goes through - there's no guarantee that the processing was successful.

    target is a variable, not a constant, so i can't put it in quotes.

  7. Yes, it works until I run swapContent().

     

    No, just a single run, not whenever found on the page through soft refresh.

     

    I solved it temporarily with a hard refresh just for that page.

     

    I'm asking why it only triggers once on the page in the jquery forum: https://forum.jquery.com/topic/errors-between-ajax-and-accordian

     

    It could be a bigger problem than just accordion.

  8.  The code you suggested I use broke, so I'm now trying to go from:

    function swapContent(href, url_data, target) {
        $.ajax({
            type:'get',
            url:href,
            beforeSend:function(){
                target.innerHTML="Doing something - please wait.";
            },
            data:url_data,
        }).done(function(ajaxObject){
            var resp = JSON.parse(ajaxObject);
            if(resp.success == true){
                target.innerHTML="Woot!";
            }else{
                target.innerHTML='Processing error - system returned false!';
            }
        }).error(function(){
            target.innerHTML='System error - not processing related!';
        });
    }
    

    The error I get is "Uncaught SyntaxError: Unexpected token <"

    crashed on:
    Doing something - please wait.

     

    Your $('#target') it didn't run.

  9. I use this for my ajax ATM:

    function swapContent(href, url_data, target) {
    $.ajax({
    type: 'GET',
    cache: false,
    url: href+'?' + url_data, //add a variable to the URL that will carry the value in your i counter through to the PHP page so it know's if this is new or additional data
    success: function (data) { // this param name was confusing, I have changed it to the "normal" name to make it clear that it contains the data returned from the request
    //load more data to "target" value div
    target.innerHTML = (data); // as above, data holds the result of the request, so all the data returned from your results.php file are in this param but please see below
    }
    })
    }
  10. What exactly is a "soft refresh" in your mind?  If it stops working after an ajax load are you sure there isn't a javascript error in the console after the ajax?

    soft refresh (ajax call) is like a soft start on a computer (software reset)

    hard refresh (f5) is like a hard refresh on a computer (shut down, and power on again)

     

    The error is the accordion breaks, so it's an id10t error, not a syntax error.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.