Controller file not being executed

So what I am trying to do is get some data from user in a form and as user presses submit button, the data should be added in the Lead’s module database. But the issue which is coming is that the controller file(controller.php) is not being executed. even though the control reaches to the ajax success function.

Following is the index.html code:

<!DOCTYPE html>

<html>

<head>

<title>Submit Form Using AJAX and jQuery</title>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

<script src="./script.js"></script>

</head>

<body>

<h2>Submit Form Using AJAX and jQuery</h2> <!-- Required div Starts Here -->

<form action="index.php?module=Leads&action=action_insert" method="POST">

<div id="form">

<h3>Fill Your Information !</h3>

<div>

<label>Name :</label>

<input id="name1" type="text">

<label>Email :</label>

<input id="email" type="text">

<label>Password :</label>

<input id="password" type="password">

<label>Contact No :</label>

<input id="contact" type="text">

<input id="submit" type="button" value="Submit">

</div>

</div>

</div>

</body>

</html>

Following is the controller.php code :

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class CustomLeadController extends SugarController
{

    public function action_insert()
    {

        $GLOBALS['log']->fatal("I am in controller");
        return true;


    }
}

Following is script.js code:

$(document).ready(function () {

    $("#submit").click(function () 
    {
        var name = $("#name1").val();
        var email = $("#email").val();
        var password = $("#password").val();
        var contact = $("#contact").val();
       
        // Returns successful data submission message when the entered information is stored in database.
         var data ='&name2=' + name1;
         data += '&email1=' + email ;
         data += '&password1=' + password;
         data += '&contact1=' + contact
         console.log(data);   //data is printed successfully 
        
        $.ajax({
        
       // type: "POST",
        url: "controller.php",
        data: data,
        
        success: function () {
            console.log('error2');  // error 2 gets printed successfully 
          
        }
        , error: function () {
          console.log('error');
        }
        });
    });
});

In the request, try calling your action just insert

(but leave the function name as action_insert)

No its not working! What I think is that I should make an entry point in which I should place the index.html file with other name.

The request will be routed inside SuiteCRM if it has all the necessary parameters, which are probably module, action, maybe also view.

Just make sure you follow the conventions, the easiest way is to copy an existing AJAX request. I suggest taking a thorough look at this one (which uses the controller of a special module called “Home”):

→ https://github.com/salesagility/SuiteCRM/blob/master/include/InlineEditing/inlineEditing.js#L549

→ https://github.com/salesagility/SuiteCRM/blob/master/modules/Home/controller.php#L49