0

I'm using JQuery Ajax on my website. I've tested it on our test server it worked perfectly, but when I tried to put it on our productive server the Ajax just returns the source code of the website itself.

JS File:

$(document).ready(function () {
    $('#sshin').keyup(function () {
        var query = $(this).val();
        console.log(query);
        if (query != '') {
            $.ajax({
                url: "search.php",
                method: "POST",
                data: {
                    query: query
                },
                success: function (data) {

                    console.log(data);

                }
            });
        }
    });

    $(document).on('click', 'article', function () {
        var text = $('#sshin').val();
        text = text.substring(0, text.lastIndexOf(',') + 1);
        text += $(this).text();

        var uniq = text.match(/\b\w+\b/g).filter(function (el, idx, a) {
            return idx === a.lastIndexOf(el);
        });

        text = uniq.join(',');

        $('#sshin').val(text);
        $('#sshout').fadeOut();
    });
});

PHP File:

<?php
  if(isset($_POST["query"])){
     $query = $_POST["query"];
     return '<ul><li>1</li><li>2</li></ul>';
  }
?>

Any idea why it returns something different than it should?

14
  • 1
    What do you mean by "source code of the website itself"? Can you post an example bit? Commented Jan 12, 2017 at 11:53
  • 2
    Nothing wrong with ajax. see the implementation of search.php Commented Jan 12, 2017 at 11:53
  • Possibly related: stackoverflow.com/questions/7264014/… Commented Jan 12, 2017 at 11:53
  • @Pekka웃 it's litterally the html code from the file Commented Jan 12, 2017 at 11:54
  • Is it any possibility that you forget to use a parser of your PHP files? Commented Jan 12, 2017 at 11:54

1 Answer 1

0

This method once worked for me, hope it might help. Let me know.

 this->output->set_content_type('application/json');
        return $this->output->set_output(json_encode('<ul><li>1</li><li>2</li></ul>'));
Sign up to request clarification or add additional context in comments.

2 Comments

@Damon just remove the return '<ul><li>1</li><li>2</li></ul>'; of your code. and then paste this and check what console.log(data) shows.
removed this and it works, but still returns the source code.. maybe it helps i found this: https://myserver.ch/search.php?query=test,etc when you go into inspect in chrome and then on network..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.