Welcome Guest, Not a member yet? Register   Sign In
Wierd ajax bug
#1

[eluser]Aviatrix[/eluser]
Hello , when i try to make AJAX request with jQuery as a response i get the html of the same page !

here are my files

the ajax controller :
Code:
Class Ajax extends Controller {
    
    function process(){
    
        $data['url'] = $this->input->post('url');
        $this->load->view('test',$data);
        echo "hello world";
    }

}

the JS :
Code:
[removed]
            $(document).ready(function(){
                $("#inv").hide();
            });
            $(document).ready(function(){
                $("#submit").click(function(evt){

                    $.post("/ajax/process/", {
                        url: $("#url").val()
                    }, function(response){
                        $("#output").html(""),
                        $("#inv").show("slow"), $("#output").html(response)
                    }, "text");
                    evt.preventDefault();
                });
            });
        [removed]

the htaccess ( i think this might cause all the problems )
Code:
RewriteEngine on

RewriteCond $1 !^(index\.php|images|robots\.txt|(.*).js|(.*).css|(.*).jpg|(.*).png)

RewriteRule ^(.*)$ /index.php/$1 [L]
#2

[eluser]theprodigy[/eluser]
Quote:$.post("/ajax/process/", {
url: $("#url").val()
}, function(response){
$("#output").html(""),
$("#inv").show("slow"), $("#output").html(response)
}, "text");

Try changing to:
Code:
$.post("/ajax/process/", {
    url: $("#url").val()
}, function(response){
    $("#output").html("");
    $("#inv").show("slow");
    $("#output").html(response);
}, "text");

Inside the "success" function, you should end each line with a semi-colon, not a comma.
#3

[eluser]Aviatrix[/eluser]
tried that .. same result
#4

[eluser]theprodigy[/eluser]
Quote:Class Ajax extends Controller {

function process(){

$data['url'] = $this->input->post('url');
$this->load->view('test',$data);
echo "hello world";
}

}

What is in the view that you are loading? Is it the same view you are loading in the first place?
#5

[eluser]Aviatrix[/eluser]
[quote author="theprodigy" date="1265001663"]


What is in the view that you are loading? Is it the same view you are loading in the first place?[/quote]

thats in the view , and yes it is the same
Code:
<?php echo $url ?>
#6

[eluser]theprodigy[/eluser]
so, how are you showing the view in the first place? What controller/function?
#7

[eluser]Aviatrix[/eluser]
thats the main controller & the view that it loads

Code:
Class Main extends Controller {
    
    function Main()
    {
          parent::Controller();  
    }
    
    
    function index(){
        
        $this->load->view('oxila_index');
    }
}


Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
    &lt;head&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
        &lt;title&gt;Short URls FTW! - Oxi.la&lt;/title&gt;
        &lt;link href="./style.css" rel="stylesheet" type="text/css" /&gt;
        &lt;!--[if lte IE 5.]>
            [removed][removed]
        <![endif]--&gt;
        [removed]
        [removed]
        [removed]
            $(document).ready(function(){
                $("#inv").hide();
            });
            $(document).ready(function(){
                $("#submit").click(function(evt){
                                            
                    $.post("/ajax/process", {
                        url: $("#url").val()
                    }, function(response){
                        $("#output").html("");
                        $("#inv").show("slow");
                        $("#output").html(response);
                    }, "text");
                    evt.preventDefault();
                });
            });
        [removed]
    &lt;/head&gt;
    &lt;body id="body"&gt;
        <div id="mainframe">
            <div id="logo">
            </div>
            <br/>
            <div style="clear:both;"/>
                <div id="content">
                    <div id="urlform">
                        &lt;form id="post" method="post" action="/ajax/process"&gt;
                        <div id="button">
                            &lt;input type="submit" id="submit" value="Shorten" /&gt;
                        </div>
                        <div id="input">
                            &lt;input type="text" name="url" id="url" /&gt;
                        </div>
                        <div style="clear:both;"/>
                        &lt;/form&gt;
                        <div id="submenu">
                            <a href="register.php" title="Register">Register</a>
                            | <a href="login.php" title="Log in">Log in</a>
                        </div>
                        <div style="clear:both;"/>
                            <div id="inv">
                                <div name="inv" id="outputDiv">
                                    <span name="inv1" id="output"></span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            &lt;/body&gt;
        &lt;/html&gt;


here is a live preview http://oxi.la
#8

[eluser]mattpointblank[/eluser]
Try changing your function to this:

Code:
function process(){
    
        $data['url'] = $this->input->post('url');
        $page = $this->load->view('test',$data, TRUE); // saves view to a string
        echo $page;
    }
#9

[eluser]Aviatrix[/eluser]
nope , same thing ... :S im geting desperate here .. i tried 0498958367 tutorials .. same thing .. :S
#10

[eluser]theprodigy[/eluser]
Quote:thats in the view , and yes it is the same
&lt;?php echo $url ?&gt;

When I visit http://oxi.la/ajax/process, I get a submit button and a text field. It just doesn't display like the home page because of the relative path to the javascript and css files. Do you have some code in place that shows the home page on 404, or maybe something in your routes file to send everything to the home page?




Theme © iAndrew 2016 - Forum software by © MyBB