Ajax and ossn object not work

Malik Umer Farooq Posted in Technical Support 6 years ago

I write simple ajax script but it does not work when i type in box page hang-up and reload everything gone to hide
Here is snapshot of mu ajax code
enter image description here

And i want search value i write search script it return all result
Here is snap
enter image description here

Help me please

Replies
German Michael Zülsdorff Replied 6 years ago

> i dont know where you see alert box my jquery code

the alert box is HERE in this thread top of page 2, you yourself made a screenshot of it yesterday!

But you even changed the javascript in the meantime.
Why are you doing all these things?
Your code is getting more and more confusing.
I only told you to remove the ifs from page.php, simplify that page to 1 function and save the rest of code somewhere else.

pk Malik Umer Farooq Replied 6 years ago

I think jquery.post is use for sending and load server http response in backend without refrsh page and i am not doing like that

    $.post(Ossn.site_url+'/helpsearch',{action:search},function(data){
             location.reload(); 
        });
pk Malik Umer Farooq Replied 6 years ago

i dont know where you see alert box my jquery code
i already remove this when you say but i was use for test purpose
enter image description here

German Michael Zülsdorff Replied 6 years ago

Malik you don't have to tell me again and again that it does not work.
I know that. :)

And I was trying to explain why already 20 hours ago:
"But on the other hand (see the code in your alert window) you are telling jquery to do a complete reload of the Help page."

You had copied some code you don't understand,
so next is to simplify the code first
Dont't be so impatient ... it still needs some steps ...
just follow my instructions ...

pk Malik Umer Farooq Replied 6 years ago

page.php

 <div class='form-group'>
    <input type='text' id='search' class='form-control' placeholder='Search question....'/>

</div>
<span class='search-result'></span>

search.php

    <?php
echo input('action');
?>

these not work show same error as before
i also check page.php

 <?php
/**
 * @Name HelpDisk
 *
 * @package ossn Component
 * @author Malik Umer Farooq
 * @copyright 2017 Malik Corporation Private limited
 * @license   General Public Licence https://my-mos.com/public/terms/ 
 * @link      https://my-mos.com/public/
 */
    $help = new HelpDisk;
    $questions = $help->getQuestion();
    $count = $help->getQuestion(array(
            'count' => true,                                     
    ));
 ?>

     <div class='form-group'>
        <input type='text'id='search'class='form-control' placeholder='Search question....'/>
     </div>
     <div id='control'> 
        <div class='panel panel-default'>
        <div class='panel-heading'>
            <h1 class='panel-title'><?= ossn_print('helpdisk:help'); ?></h1>
        </div>
        <div class='panel-body'>
        <?php foreach ($questions as $value){ ?>
        <a href='<?= ossn_site_url(); ?>/Help?q=<?= $value->guid; ?>'id='questions'><?= $value->title; ?></a><br>
        <?php } ?>
        </div>
        </div>
<?php
echo ossn_view_pagination($count);  ?>
 </div> 
<?php if(input('q')){ 
     $guid = input('q');
    $specific_question = $help->helpGetByGuid($guid); ?>
        <div class='panel panel-default'>
        <div class='panel-heading'>
            <h1 class='panel-title'><?= $specific_question->title ?></h1>
        </div>
        <div class='panel-body'>
            <p><?= $specific_question->description; ?></p>
        </div>
        </div>

<?php } ?>
<span id='search-result'></span>

this not show any error also not work at all the word i enter should be display

German Michael Zülsdorff Replied 6 years ago

Malik,
you still don't understand.

I did not say: "Replace all $_GET by the input function"

I said: "Remove all those $GET, $POST conditions from page.php
and reduce it to have only one basic function"

This page will have only ONE function - so it needs no if (this) { do something ... }

Indonesian Arsalan Shah Replied 6 years ago

Malik when you change the code did you tested it ? you must get errors , did you enabled error log? Because

if(empty(input("q") and empty(input("search")))){

You can not pass the functions to empty() function and the above statement have alot of syntax errors.

pk Malik Umer Farooq Replied 6 years ago

i create another page search.php and setting up in ossn_com.php file i add following in the search file

    <?php if(!empty(input('action'))){
    echo input('action'); 
}
?>

and my jquery code become

    $(document).ready(function() {
    $('#search').keyup(function(){
        $('#control').css({'display':'none'});
        var search = $('#search').val();
        $.post(Ossn.site_url+'/helpsearch',{action:search},function(data){
                $('.search-result').html(data);
            });
    }); 

});

page.php become

    <?php
/**
 * @Name HelpDisk
 *
 * @package ossn Component
 * @author Malik Umer Farooq
 * @copyright 2017 Malik Corporation Private limited
 * @license   General Public Licence https://my-mos.com/public/terms/ 
 * @link      https://my-mos.com/public/
 */
    $help = new HelpDisk;
    $questions = $help->getQuestion();
    $count = $help->getQuestion(array(
            'count' => true,                                     
    ));
    if(empty(input('q') and empty(input('search')))){
 ?>

     <div class='form-group'>
        <input type='text'id='search'class='form-control' placeholder='Search question....'/>
     </div>

     <span class='search-result'></span>
     <div id='control'> 
        <div class='panel panel-default'>
        <div class='panel-heading'>
            <h1 class='panel-title'><?= ossn_print('helpdisk:help'); ?></h1>
        </div>
        <div class='panel-body'>
        <?php foreach ($questions as $value){ ?>
        <a href='<?= ossn_site_url(); ?>/Help?q=<?= $value->guid; ?>'id='questions'><?= $value->title; ?></a><br>
        <?php } ?>
        </div>
        </div>
<?php
echo ossn_view_pagination($count); } ?>
 </div> 
<?php if(!empty(input('q'))){ 
     $guid = input('q');
    $specific_question = $help->helpGetByGuid($guid); ?>
        <div class='panel panel-default'>
        <div class='panel-heading'>
            <h1 class='panel-title'><?= $specific_question->title ?></h1>
        </div>
        <div class='panel-body'>
            <p><?= $specific_question->description; ?></p>
        </div>
        </div>

<?php } ?>
<span id='search-result'></span>

and i updated code on github please help me these also not work at all
https://github.com/Lablnet/HelpDisk
it also have same output as before not work at all here is image of output
enter image description here

> That's like "Hey, give me a new bottle of beer - but with the old beer I had drunk already"

i don't think it much be submit jquery post in another page so thats reason i do that and I change code still same issue

> not allowed (remember Arsalan told you NOT to use $_GET and similar !!!)

Sony for unfollow your team instruction but I change code still same issue

German Michael Zülsdorff Replied 6 years ago

Okay, so what's wrong with your code?

Your Help page is based on that old 'all-in-one' PHP concept - having an inside page handler.

So, you would call that page like all-in-one.php?action=add_name

and your code looks like

    echo 'My name is ';
    if ($_GET['action'] == 'add_name') {
    echo 'Malik';
    }
   ....
    if ($_GET['action'] == 'do_something_else') {
    echo 'unknown';
    }

With Ossn, this kind of coding is
1. not allowed (remember Arsalan told you NOT to use $_GET and similar !!!)
2. not necessary, because Ossn has its own pagehandler

That said, the next step to do is:
Remove all those $GET, $POST conditions from page.php
and reduce it to have only one basic function
Keep lines 1 to 37 plus the span with the search-result

Put the removed code in a new file - we will talk about that later.

German Michael Zülsdorff Replied 6 years ago

> i do that jquery code work but not properly

Yes,
Jquery does what you wanted. But what you wanted is (sorry) - nonsense. :)

On one hand - you wanted jquery to ADD something to the same page you are currently watching (that's why you're using Ajax)

But on the other hand (see the code in your alert window) you are telling jquery to do a complete reload of the Help page.

That's like "Hey, give me a new bottle of beer - but with the old beer I had drunk already"

Premium Version

Due to the many requests in the past for additonal features and components we have decided to develope a premium version. Features like Hashtags, Videos, Polls, Events, Stories, Link Preview, etc included in it.

$199 (Life Time)
Learn More

Other Questions