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
And i want search value i write search script it return all result
Here is snap
Help me please
So can I ask why it work for me?
And I also see these in ossn like component i think
And why the URL look like that I paste in previous post
@Malik your logic is incorrect for &
and i believe its not required in params:
You are sending post request not a get request.
> Just one question: Why are you putting this "&" in front of "search" here?
The url look like that http://localhost/ossn/action/Help/sarch?ossn_ts=value&ossn_token=value
so i need to add and & sign
http://localhost/ossn/action/Help/sarch?ossn_ts=value&ossn_token=value&search=value
because there are values already auto passed
Good work, Malik. Congratulations!
Just one question: Why are you putting this "&" in front of "search" here?
params: "&search=" + search,
Very Thanks you sir zet man now ossn post method work fine
here is my js code
$(document).ready(function() {
$('#search').keyup(function(){
$('#control').css({'display':'none'});
var search = $('#search').val();
Ossn.PostRequest({
url: Ossn.site_url + "action/Help/search",
params: '&search=' + search,
callback: function(callback) {
console.log('returned val is: ' + callback['data']);
},
});
});
});
search page code
<?php
$data = input('search');
echo json_encode(array(
'data' => $data,
'process' => 1
));
> but i am at grade 11 i learn everything upto online
Don't worry, I am always remembering this - right that's why I stay patiently with you to bring this to a good end - even if it takes some time ... ;)
I think, you have learned a lot already in these two weeks, but you still tend to just copying some code and replacing some vars by your own ones - without understanding which way the code is exactly working. And that's not the right way of programming.
Your latest change is the best example: You copied some code from the Comments section, replaced that form: "#comment-container-" + $container
, by your form: "#search-question" + search ,
without checking for what it is good for!
Time to use our development console again and verify:
And aha! What we see is: comment fields are using a HTML form tag, and each of these forms can be identified by a different unique ID. Otherwise Ossn wouldn't know WHICH field you are using. That means: the line form: "#comment-container-" + $container
actually is addressing a form with an id on that page.
Consequently, the next question you should have asked yourself:
- Do I have a form with id=search-question
on my page.php?
And the clear answer is: NO, There is no such form on page.php. :(
That's why your form: "#search-question" + search ,
is absolutely useless.
> Always try to understand a function first, before making use of it.
Aside from using the development console, always have a look INTO the function you are trying to use. Open the Ossn Javascript core library system/plugins/default/javascripts/libraries/core.php
And on line 35 you will already note from Arsalan's comments, that this function is dealing with forms. And since you have no form in page.php you could have known in advance that your code would not work.
Okay, so what's next? One way to solve the problem could be to add a form to page.php. But since I told you to keep that page simple, there's an easier way: Just scroll some lines down in the Javascript library, and you will find Ossn.PostRequest()
which will work without a form.
Use this function, and for now please revert your helpsearch action to the old code:
<?php
error_log('hello, this is helpsearch!');
echo input('action');
i change to this
form: "#search-question" + search ,
#search-question
is form id
search
is search variable that get value like that
var search = $('#search').val();
.
url: Ossn.site_url + "action/Help/search"
this also not work
I see those in ossncomment component
@zet man sir i think you are software engineering but i am at grade 11 i learn everything upto online (relate to programming)
Thumbs UP Malik,
still not working, but you are on the right way using an available Ossn function instead of 3rd party stuff you found somewhere else. (That's what I meant in the very beginning: "Make friends with your programming environment, first).
Okay, so let's have a look into your new stuff:
url: Ossn.site_url + "action/Help/search/"
,url: Ossn.site_url + "action/Help/search"
form: search
, ?!? I don't understand what this code should do? Please explain.I see Ossn.Ajax.... function so i try used that but useless
$(document).ready(function() {
$('#search').keyup(function(){
// alert('working');
$('#control').css({'display':'none'});
var search = $('#search').val();
//alert(search);
console.log('search val is: ' + search);
/* $.post(Ossn.site_url+Ossn.Config['ossn_ts']+Ossn.Config['ossn_token']"action/Help/search",{action:search},function(data){
//$('.search-result').html(data);
// alert(data);
console.log('search val is: ' + data);
});*/
Ossn.ajaxRequest({
url: Ossn.site_url + 'action/Help/search/',
form: search ,
callback: function(callback) {
if (callback['process'] == 1) {
console.log('return val is: ' + callback['data']);
}
}});
});
});
i see comment component so i also change search file in action
<?php
$data = input('action');
echo json_encode(array(
'data' => $data,
'process' => 1
));
but not work at all
> my hints.
My last tip was trying to find any other occurrence of "$.post(Ossn.site_url" in Ossn code. So did you?
yes i find this but in only my js file
C:\wamp64\www\ossn\components\Helpdisk\plugins\default\helpdisk\js.php (1 hit)
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)