1

I have an external end point

localhost:5000 which loads a simple html page with an image. A flask server is running there which serves html content.

I have another html file called index.html . In the index.html, I have a div called movie-data . I want to make a Ajax request localhost:5000 and append the html content in the div movie-data of index.html .

index.html :-

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>

function init() {

$.ajax({
    dataType: "html",
    url: "http://localhost:5000",
    success: function (data) {
        console.log(data);
        $("#movie-data").html($(data).append(data));
    }
});

init();

</script>

<div id="movie-data"></div>

It is showing error,

Uncaught SyntaxError: Unexpected end of input
init();
3
  • 1
    NB: Think about what $(data).append(data) does.... It makes no sense. Commented Dec 2, 2018 at 19:22
  • 1
    if you use .html, it will replace old data, if u use append, it will append, check my answer Commented Dec 2, 2018 at 19:24
  • let me know if it works Commented Dec 2, 2018 at 19:36

1 Answer 1

1

no closing tag of function was found

fix : -

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>

function init() {

  $.ajax({
    dataType: "html",
    url: "http://localhost:5000",
    success: function (data) {
        console.log(data);
        $("#movie-data").append(data);
    }
  });
}

init();

</script>

<div id="movie-data"></div>
Sign up to request clarification or add additional context in comments.

2 Comments

it is working. If I want to append data in iframe , do you have any suggestion ?
Set a div in iframe with an id suppose framediv and then append data in it as framediv.append(data)

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.