Delete html in action

Hi,

I am creating a new action in a module, to call from ajax but return the html of all suitecrm, my cuestion is how remove the html in the action.

thanks

cuestion? you mean question? :woohoo:

yes use :



die();

At the end of your php code in the action.

But I still appears html code, when I access the url of the module and action appears html and I want this blank, and add the die does not work.

You obviously are not calling the action via ajax.

You will have to give me more details on what your doing.

Post the code for your custom action.

That’s what I want to do, call via ajax to my action, as I do or what is the equivalent to make a call via ajax

Look in the projects module for examples of how to do it:

modules/Project/js/main_lib.js

modules/Project/controller.php

here is an example using jquery to make the ajax call


//Ajax call to the action_get_end_date() function in controller.php
    //Returns the end date of predecessor with the lag added
    $("#Predecessor").on('change', function() {

        if($('#task_id').val().length == 0){
            var Id = $(this).find(":selected").attr('rel');
            var Lag = $('#Lag').val();
            var dataString = '&task_id=' + Id + '&lag=' + Lag;
            $.ajax({
                type: "POST",
                url: "index.php?module=Project&action=get_end_date",
                data: dataString,
                success: function(data) {
                    $("#Start").val(data);

                }
            });
        }
    });

the above code calls the following function in the controller:



 //Returns new task start date including any lag via ajax call
    function action_get_end_date(){
        global $db,  $timeDate;

        $timeDate = new TimeDate();
        $id = $_POST['task_id'];
        $lag = $_POST['lag'];

        //Get the end date of the projectTask in raw database format
        $query = "SELECT date_finish FROM project_task WHERE id = '{$id}'";
        $end_date = $db->getOne($query);
        //Add 1 day onto end date for first day of new task
        $start_date = date('Y-m-d', strtotime($end_date. ' + 1 days'));
        //Add lag onto start date
        $start_date = date('Y-m-d', strtotime($start_date. ' + '.$lag.' days'));

        echo $timeDate->to_display_date($start_date, true);
        die();

    }