can't show data when refreshing page with jquery-ajaxy - php

I try to create an ecommerce website with codeignitier. i'm using ajax to load the picture into div and jquery-ajaxy to show the url, it works well for backward and forward button, but
i got a problem when i refreshed the page, the data can't be show in the div.
is there anyone know why this happen??
controller
function tesa() {
$this->load->view("apricots.html");
}
function tesb() {
$this->load->view("bananas.html");
}
function tesc() {
$this->load->view("coconuts.html");
}
view
a href="./index.php/index_con/gambar/Kategori/Sarung/Apple/K001" class="ajaxy ajaxy-page"
Learn about Apricots

i forget to replace the state on Page Controller's "Matches" in the script ..
problem solved :D
thanks

Related

Codeigniter: Controller cannot load view

I am trying to load a view from a controller but i am not able to do so? I am not getting any error but the view doesn't appear. In the search input field of my page i use ajax to get suggestions from the db for the typed in text:
function get_users($hint)
{
if($hint!="")
{
$this->db->select('email,first_name');
$this->db->like('email',$hint,'after');
$query=$this->db->get('users');
$row=$query->result_array();
$name=$row[0]['first_name'];
echo "<a href=/codeigniter/index.php/user_view/view_profile/$name >".$name."</a><br>";
}
else
{
echo "";
}
}
This sends the name of user as a link to the view. When i click the link it calls a controller which then loads the profile of the user (say whose name is contained in $name).
the code of that controller is
function view_profile($name)
{
$data['user']=$name;
$this->load->view('profile',$data);
}
A new page opens but the profile doesn't load. It's just a blank page. Can anybody help?
Why not redirect to user_view/view_profile right from get_users function?
I mean instead of echo "".$name."";
you may try to write redirect('user_view/view_profile/'.$name);
And one more thing in config/config.php enable logs (If you haven't enabled them yet) , log files are so usefull in troubleshooting.

change value of a php variable on ajax content load

I thought this would be really simple but obviously after a couple of days trial and no success I have to ask the people to help, looked everywhere.
right im basically creating a php template without much guidance on the foundation 4 framework with is a responsive framework. Now this framework is rather basic and so to add page transitions ive had to use jquery to do what i believe is an ajax call to take "content" from another page and display it on the template page index.html
for which I am currently using the following
<script>
$(document).ready(function() {
$('nav.top-bar > section.top-bar-section > ul.right > li > a').click(function() {
var toLoad = $(this).attr('href')+' #content';
$('#content').hide(1000,loadContent);
$('#load').remove();
$('#main_wrapper').append('<span id="load">LOADING...</span>');
$('#load').fadeIn('fast');
window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-0);
function loadContent() {
$('#content').load(toLoad,showNewContent);
}
function showNewContent() {
$('#content').show(1000,hideLoader);
}
function hideLoader() {
$('#load').fadeOut('fast');
}
return false;
});
});
</script>
NOW before i changed over to using ajax and jquery i was operating the menu "active" class and the page name with a simple variable set on each page in the first line listed as $page='' and then the page name
now that im loading the content with ajax even if i include this variable in the content of the new page it will not update in either the or the menu title
im very sorry i dont write things correctly im new to this forum thing
thank you for the help in advance
:) I prefer someone to explain what i need to do and how to do it rather than just copy and pasting code as im a learner :)
You probably want to load the page and parse the result in jQuery to get the new page’s <title> tag and set the requesting page’s <title> tag.
The only thing I’d ask is: why are you doing this? Are you just wanting AJAX page navigation in your website instead of the traditional propagating navigation?
I am only able to answer one part of your question due to extreme confusion, so:
First off, here's why your url changes:
window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-0);
You are modifying it with that line. That line, however, has an interesting little quirk:
attr('href').length-0
at the end. Why the -0? That would make no difference. I'd clean it up.
Outside of that, I'm incredibly confused with what you're asking so let me try rephrasing it and you can tell me what I'm missing.
You want to have a user click on a navigation link, and load that link's content via an AJAX call using jQuery, and then replace the content on the page with the newly loaded page, correct?
When you say "right on top main page i have variable $page = then the page name", what do you mean by "main page"? Do you mean it's a line of text in HTML? Part of a script that you haven't included here? Part of your PHP code?
And then you say "ive tried including the tag in a div that changes along with the above content"- what is "the tag"?
By reading this 4 or 5 times I could barely discern the above understanding of what you're trying to do.
Please make heavy edits to you question- it's incredibly hard to understand.
Lastly, why are you trying to replace the browser's functionality of a user clicking a link and loading content? That's what the browser is for. The browser also, conveniently, has a loading indicator in the url bar usually (or some form thereof), letting the user know the content is still loading.
function loadContent() {
$('#content').load(toLoad,showNewContent);
}
So first off, look at the jQuery doc for the load method:
http://api.jquery.com/load/
Your issue is that it is calling for three arguments, and you are passing two. If there are multiple arguments listed and you only want to pass SOME of them, you still need to supply a null value for the ones you want to "skip". Try changing your call to this:
function loadContent() {
$('#content').load(toLoad, null, showNewContent);
}
You'll notice that I'm passing "null". If that doesn't work, pass an empty string, like this:
function loadContent() {
$('#content').load(toLoad, "", showNewContent);
}
That second argument is data to be passed with the request. It's the THIRD argument that you list as your callback, which as far as I can tell is where you're making the mistake.

Data from Formlayout do not get saved in the database

I am using CodeIgniter and DHTMLX to build my system. When my site first loads it show the DHTMLXGrid with all the data from the DB. And when I click on a record and press edit button, it will show the Formlayout.
In my form first field is description and then a checkbox which will enable few other select boxes. If i didn't change the checkbox status data won't get save in the DB. I have no idea what is wrong in my code. I am new to this. Any help would be highly appreciated.
workbench.js
if(buttonid=='save') {
eval(formSaveCallback);
myFormbar.validate();
if (defFrmSaveHandling) {
dhxLayout.cells('b').collapse();
search.grid.updateFromXML(search.grid.xmlLoader.filePath,true,true);
}
}
datalibrary.js
function Save(){
addForm.send(layoutBench.formDataUrl+'add/', "post", function(loader, response){
if (debug) console.log('Save return code is :-',response);
if(response==1) {
$('#info').fadeIn();
$('#info').html('Data is saved successfully');
$('#info').fadeOut(3000);
}
});
}
My controller and model works fine. I think the issue is because of the blur is not fired when I do not click on any other controls after adding the description may be if I can give a delay and enable the save buton it will work. But I don't no how to do that.
Any help regarding the matter?
Thanx.
I come up withe the answer to this.
It is that I have to call the blur function at the beginning of the save function.
function Save(){
addForm.getInput("description").blur();
//rest of the code
}

How do I fully refresh the page in CodeIgniter?

I am loading a form in an overlay. The overlay has a separate controller and action to the page that invokes the overlay.
On form submit, if successful, I simply want to reload the referring page that the overlay was loaded from. I can get the referring page to load, but it places the content inside the overlay.
header("Location: www.example.com", true, 302);
does not work.
Using the URL helper like this:
$url = $_SERVER['HTTP_REFERER'];
redirect($url);
Also does not work. Every time it loads in the overlay. I am sad because of it.
You can use this code to refresh in codeigniter:
redirect($_SERVER['REQUEST_URI'], 'refresh');
it should work!
This one is more simple
redirect($this->uri->uri_string());
Unfortunately, using header to refresh/redirect will only reflect the changes in the container that is displaying the PHP page.
To refresh the parent page (i.e. the page that is displaying the overlay itself), you will need to do it on the client-side using Javascript. These questions should help you get on the right path:
Redirect parent window from an iframe action
PHP "header (location)" inside IFRAME, to load in _top location?
You can use this code to refresh in codeigniter:
redirect($_SERVER['REQUEST_URI'], 'refresh');
Hope this helps.
You do not have to supply additional two arguments for header. Just use this pattern:
header('Location: www.somewhere.com');
Also, check out this article about a similar matter:
Redirect with CodeIgniter
redirect(site_url(strtolower(__CLASS__)));
It's just
redirect('/some_url', 'refresh');
First load under constructor method like as:
function __construct()
{
parent::__construct();
$this->load->library('user_agent');
}
After inserting or update add this method it will work fine.
redirect($this->agent->referrer());
This one is more simple for everone :)
location.reload()

php post without form

I have a php page that takes some get strings, after some user interaction I want to continue executing some php code without navigating or refreshing the page so that its smooth and doesn't flicker. Ive tried secretly clicking invisible forms and it always refreshes, how can achieve this?
Also as a side note, I am using jquery but I was not able to get that post function up and running, I will keep trying it but let me know if that is a wrong solution.
//gallery.php
//jquery
$(".download").click(function()
{
$.post("gallery.php", { images: "testing it out" } );
});
<?php
if(isset($_POST['images']))
{
echo "It worked";
}
else if(isset($_GET['artist']))
{
echo "It worked2";
}
?>
They are both in the same page, the get always works because I pass the info though the url from another page. But the .download click doesnt cause the php code under post to execute
Use Ajax to send a HTTP request in the background.
Using Ajax is the solution...
You can try with jQuery, read this link http://api.jquery.com/jQuery.post/
jquery ajax is very simple method for post a form without page refresh ..
read more about ajax
Are you thinking of AJAX?

Categories