skip to Main Content

I am really stuck at this point and after 4 Hours of trying everything what I found or came up with but nothing works and I can’t explain myself how the error is producing…

So basiclly I have my file which displays content dynamically by calling with jQuery some background PHP and fills the data in the predefined HTML tags. When running this for the first time, there is no problem and everything works fine. But when I want the second content it tells me that the $.post is not a function.

<script>
    $(document).ready(function(){
        //hide the predefined html
        $("#DIV_editContent").hide();
        $("#A_edit").css({"font-weight":"bold","border-left":"1px solid black","border-right":"1px solid black"})
        //create array to store the clientnames
        var clientArray = [];
        //get all the clients from php and push them into the array
        $.post("pages/allClients/callClientlist.php",function(data){
            var jsData = JSON.parse(data);
            
            $.each(jsData, function(index,clientname) {
                clientArray.push(clientname);
            });
        });
        //console.log(clientArray);

        //function to call some extra data
        function outComponents(json){
            $.post("pages/editClient/outputEditComponents.php",{"components":json})
                .done(function(response){
                    $("#DIV_componentList").html(response);
                });
        };

        let currentClient = "";
        //main function to call the data with all the relations
        function callData(clientSelection){
            //console.log("client:"+clientSelection);
            
            //the error will occure here the second time when calling this
            $.post("pages/allClients/getClient.php",{"client":String(clientSelection)},function(){console.log("inside")})
                        .done(function(userData){

                            //fetching some data to variables and insert it into the HTML
......
......
                                $("#H2_clientName").html("<span style='text-decoration: underline;'>Bearbeite:</span> &emsp;" + clientName)
                                
                                //file to insert the data to HTML
                                <?php include_once "pages/editClient/fillEditData.js" ?>
                                //call the function for some extra data
                                outComponents(jsonComponent);

                                //set the session params to jump between pages without losing the asked content
                                $.session.set('lastClient',clientName);
                                $.session.set('components',jsonComponent);
                                //show the HTML
                                $("#DIV_editContent").show();
                        });
        };
        
        let lastClient = "";

        //autocomplete feature to search for client names when an object is selected the function above will be called
        $(function(){
            $("#EDIT_searchClient").autocomplete({
                source: clientArray,
                autoFocus: true,
                select: function(event,ui) {
                    var selection = ui.item.value;
                    callData(selection);
                    console.log(selection)
                }
            });
        });
    })
</script>
<!-- predefined HTML -->
<div id="DIV_editClientMain">
    <div id="DIV_search">
        <input type="search" placeholder="Suchen..." id="EDIT_searchClient">
    </div>
    <div id="DIV_editContent">
        <div id="DIV_editData">
            <?php include_once "pages/editClient/editClientForm.html"; ?>
        </div>
    </div>
</div>

When there should be missing a () or {} to close, then it is because I snipped a few lines code out to show it properly here.

  • I tried to change the $.post to $.getJSON because the all the php will return json, but without success.
  • I checked everything in the other files and no error or wrong outputs from them
  • Played around with console.log to see where exactly the error occures. The first time running, everything works fine, the second time he gets the value from the autocomplete feature, but the $.post will throw an error…
  • Checked if the value from autocomplete is the right content and right type.
  • And checked a lot of small things ex. running the code with the limited amount of data needed to fullfill the code but nothing changed

2

Answers


  1. Chosen as BEST ANSWER

    Thank you @Mimoudix!

    It seems like the $.noConflict() method worked. I include some other js files for further features and it seems like these are the problem, but with this method the error is fixed and everything works as normal :) would not have solved this on my own^^

    I linked these files:

    <link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel = "stylesheet">
    <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
    <script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
    <script src="js/jquerysession.js"></script>`enter code here`
    

  2. It seems like the issue is that the $.post function is not being recognized when you call it the second time. One possible cause is that jQuery is not being included correctly in your HTML document. You can check this by adding a console.log statement to print the version of jQuery you’re using

    console.log($.fn.jquery);
    

    Another possibility is that there is a conflict between different versions of jQuery. You can try using jQuery’s noConflict() method to avoid conflicts.

    var jq = $.noConflict();
    

    This will assign the jQuery object to the variable "jq", which you can then use instead of the "$" symbol to call jQuery functions.

    If neither of these solutions works, it may be helpful to provide more information about the specific error message that you’re seeing and any other relevant details about your code and environment.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search