Have the following code?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script> var catalog = "", pagen_1 = 1; $.ajax({ url: "https://cors-anywhere.herokuapp.com/http://vm1.culture.ru/abramtsevo/catalog/ajax.php", data: { PAGEN_1: pagen_1, EAR_SEARCH_LEFT: "-99", YEAR_SEARCH_RIGHT: "1999", TEGS: "Живопись" }, type: 'POST', success: function(catalog) { catalog += catalog; for (; ; pagen_1 <=10) { url: "https://cors-anywhere.herokuapp.com/http://vm1.culture.ru/abramtsevo/catalog/ajax.php", data: { PAGEN_1: pagen_1++, EAR_SEARCH_LEFT: "-99", YEAR_SEARCH_RIGHT: "1999", TEGS: "Живопись" }, type: 'POST', success: function(catalog) { catalog += catalog; }, } $("#catalog").html(catalog); }, }); </script> <div id="catalog"></div> 

Loop error:

data: {- Uncaught SyntaxError: Unexpected token:

What's the matter? And how could it be better to write this code?

Closed due to the fact that off-topic participants Grundy , cheops , rjhdby , aleksandr barakin , user207618 Oct 7 '16 at 6:40 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Grundy, cheops, rjhdby, aleksandr barakin, community spirit
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • here the $.ajax call is $.ajax and the parameter object immediately goes instead. - Grundy
  • Oh and true! Thank. Is it possible to somehow optimize this code? - Timur Musharapov
  • You can for example not send a bunch of requests before you get 10 answers - Grundy
  • Hmm, how about that? - Timur Musharapov
  • 2
    instead of an infinite loop, loop through iterations. This one for (; ; pagen_1 <=10) cycle will never end, because the condition is not written in that section - Grundy

2 answers 2

You have missed a function call.

 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script> var catalog = "", pagen_1 = 1; $.ajax({ url: "https://cors-anywhere.herokuapp.com/http://vm1.culture.ru/abramtsevo/catalog/ajax.php", data: { PAGEN_1: pagen_1, EAR_SEARCH_LEFT: "-99", YEAR_SEARCH_RIGHT: "1999", TEGS: "Живопись" }, type: 'POST', success: function(catalog) { catalog += catalog; for (; ; pagen_1 <=10) { $.ajax({ url: "https://cors-anywhere.herokuapp.com/http://vm1.culture.ru/abramtsevo/catalog/ajax.php", data: { PAGEN_1: pagen_1++, EAR_SEARCH_LEFT: "-99", YEAR_SEARCH_RIGHT: "1999", TEGS: "Живопись" }, type: 'POST', success: function(catalog) { catalog += catalog; }, }); } $("#catalog").html(catalog); }, }); </script> <div id="catalog"></div> 
     ... for (; ; pagen_1 <=10) { $.ajax({ // < - вот тут у вас проблема url: "https://cors-anywhere.herokuapp.com/http://vm1.culture.ru/abramtsevo/catalog/ajax.php", data: { ...