Call a PHP Script and after that reload

Call a PHP Script and after that reload

bill_Tombill_Tom Posts: 19Questions: 4Answers: 0
edited October 2015 in Buttons

Hello,

I need an Ajax Call witch starts an PHP Script. With the PHP Script i like to start an import.

If the import is done i like to reload my datatable (that is allready working).
How can I start the php script and work with parameter from the php-script (true - false)?

buttons: [   
            {
                text: 'Import CSV',
                action: function ( e, dt, node, config ) {
                   // PHP -Script for Import
                   var success = Call PHP-Script for Import
                   if (success = true) {
                        dt.ajax.reload();
                   }
                   else {
                       alert(Import - Error)
                   }
                }
            }

Thanks for help!
Thomas

This question has an accepted answers - jump to answer

Answers

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    Why not just use the jQuery AJAX functionality?

  • bill_Tombill_Tom Posts: 19Questions: 4Answers: 0

    I tried it with Jquery AJAX:

    var jqxhr = $.ajax("table.krempel.php1?try=1") 
    

    But I need the response from the php script. The value or boolean...

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    You would check the value returned from the PHP script using the jQuery success callback. This is the jQuery documentation for its$.ajax function.

    Allan

  • bill_Tombill_Tom Posts: 19Questions: 4Answers: 0
    edited October 2015

    Hello,
    i checked the documentation but it doesn't work.
    I do not get the response from the php script.

    var jqxhr = $.ajax({
           type:"GET" ,
           url:"table.krempel.php" ,
           data: "try=1231" ,
           async: false ,
           success: function(data) {
                 if(data == 1){
                         alert(data);
                 }
                 else {
                        alert('???' + data);
                 }
           }
    }) ;
    
    

    PHP

    if(isset($_GET['try'])){
         return 1;
    }
    
    

    Where is my mistake?

    Thx for your help.

    Thomas

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Answer ✓

    You should echo the response rather than attempting to return it. You want the PHP script to output the data that the client-side should see.

    Allan

  • bill_Tombill_Tom Posts: 19Questions: 4Answers: 0
    edited October 2015

    Hello Allan,

    ok. Understand.
    Thx a lot...

    Thomas

This discussion has been closed.