0

Display the result here at displayResult---

        <div class="form-group">
            <div align="center" class="col-md-10">
                <input  type="text" id= "contentSearch" name="contentSearch" class="form-control">
            </div></div>
        <div class="form-group"><button type="submit" class="btn btn-default" id="submitSearch">Search
            </button></div>                
    </form>
</div>

<div id="displayResult">
    {% for result in chris%}{{ result.name }}{%endfor%}  
</div>

and in ajax success--

    <script>
    $(document).ready(function () {
        $("#searchform").on('submit', function (e) {
            var data = {};
            data['contentSearch'] = $('#contentSearch').val();

            $.ajax({
                url: '/ourserver/applicants/istiak/home',
                type: 'post',
                data: data,
                success: function (returnedData) {
                    $("#displayResult").html(returnedData);// display
                }
            });

            return false;
        });
    });
</script>

But while displaying the result it is creating a from again--

before make the request --- enter image description here

After the request when display the result -- enter image description here

So it is creating the form again and also displaying the result based on the value as well.

Like if the return result is 2 time than it display twice, if the result have 3 values it will display 3 times.

so how it is possiblr to stop being duplicate from and just only display the result !!

Not multiple times, just once !!!

Anyone knows how it can be solved !!!

15
  • please post all relevant code like the entire ajax Commented Oct 14, 2015 at 8:51
  • @Pekka i have updated the question Commented Oct 14, 2015 at 8:53
  • Can you post HTML code? Commented Oct 14, 2015 at 8:55
  • can you check in the console and post here the response of the ajax call? Commented Oct 14, 2015 at 8:57
  • @AnkitSaroch yes i have update the html code as well Commented Oct 14, 2015 at 8:58

1 Answer 1

1

Try to extract the target html like this:

$("#displayResult").html($(returnedData).find("#displayResult").html());// display
Sign up to request clarification or add additional context in comments.

6 Comments

Awesome it stops creating the form again, but it is still displaying the results multiple times, i mean if the result have 3 values it is displaying 3 times, how can i stop that too as well, can you kindly suggest something !
why not just return the data as json and append them on table or list?
@Jai i have also updated the pic what it is displaying
{% for result in chris%}{{ result.name }}{%endfor%} do you have this in any other loop @IsakJohnsson?
@Jai oops my bad there was a loop, sorry and thanks a lot for your awesome answer
|

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.