0

I know I should be more specific about the problem but I don't know what it is but once I have an answer I fix the post.

Here is the problem simple ajax script but somehow it isn't working. I can't see any error on the code =/

jQuery part:

    $(document).ready(function()
{   
    var addFavPhp = '../functions/addfav.php';
    var orange = 'orange';
    var favLinkError = false;
    var favNameError = false;

    $('#addFavButton').click(function()
    {
        var favLink = $('.favLinkInput').val();
        var favName = $('.favNameInput').val();
        var fileName = $('.file').val();

        if(favLink=="")
        {
            $('.favLinkInput').css('border-color',orange);
            favLinkError = true;
        }

        if(favName=="")
        {
            $('.favNameInput').css('border-color',orange);
            favNameError = true;
        }

        if((favLinkError==false) && (favNameError==false))
        {
            $.post(addFavPhp,{favLink:favLink,favName:favName,fileName:fileName},function(addFav)
            {
                $('.favLinkInput,.favNameInput').val('').css('border-color','');
                $('.file option[value=""]').attr("selected", "selected");
                location.reload();
            });
        }
    });
});

and php part:

    <?php session_start(); 

    include('../functions/connect.php');

    if(!empty($_SESSION['username']))
    {
        $username = $_SESSION['username'];
    }else
    if(!empty($_COOKIE['PHPCOOKID']))
    {
        $cookie = htmlspecialchars(trim($_COOKIE['PHPCOOKID']));
        $explode = explode('-', $cookie);
        $username = $explode['0'];
    }

    $favLink = htmlspecialchars(trim($_POST['favLink']));
    $favName = htmlspecialchars(trim($_POST['favName']));
    $fileName = htmlspecialchars(trim($_POST['fileName']));

    $d = array($username,$favLink,$favName,$fileName);
    $req = $DB->prepare('INSERT INTO favs (username,favLink,favName,favFile) VALUE (? , ? , ? , ?)');
    $req->execute($d);

?>

What I figure out is that it stop working around $.post but I can't figure out why. And it works find on local server.

Thanks for any help.

4
  • >open chrome >hit f12 >click console >run the query >note results >click network >run the query >note results. anything? Commented Feb 18, 2013 at 19:57
  • @john POST site.com/functions/addfav.php 404 (Not Found) Commented Feb 18, 2013 at 19:59
  • @john thanks for the f12 trick, didn't know about that Commented Feb 18, 2013 at 20:07
  • no problem, its a huge lifesaver. I would also recomend getting firebug Commented Feb 18, 2013 at 20:07

1 Answer 1

1

looks like the line var addFavPhp = '../functions/addfav.php'; is wrong. you have to use http urls when doing ajax. somthing like /path/to/addfav.php

Sign up to request clarification or add additional context in comments.

3 Comments

that's weird, all other scripts have same kind of links and work fine =/, why?
might aswell closse the qustion then :)
The next time use firebug to check the php process document response.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.