0
function CallAPI(page) {
            $.ajax({

                url: "http://food2fork.com/api/search?q=chicken",
                data: { "key": "d270f61c8c9fe2ef89633f4b609966de" },
                dataType: "json",
                success: function (result, status, xhr) {
                    var resultHtml = $("<div class=\"resultDiv\"><p>Names</p>");
                    for (i = 0; i < result["recipes"].length; i++) {

                        var image = result["recipes"][i]["profile_path"] == null ? "Image/no-image.png" : "https://image.tmdb.org/t/p/w500/" + result["recipes"][i]["profile_path"];

                        resultHtml.append("<div class=\"result\" resourceId=\"" + result["recipes"][i]["id"] + "\">" + "<img src=\"" + image + "\" />" + "<p><a>" + result["recipes"][i]["label"] + "</a></p></div>")
                    }

                    resultHtml.append("</div>");
                    $("#message").html(resultHtml);

                    Paging(result["total_pages"]);
                },
                error: function (xhr, status, error) {
                    $("#message").html("Result: " + status + " " + error + " " + xhr.status + " " + xhr.statusText)
                }
            });
        }

I'm trying to display data from this API call, but I get Result: error 0 error, the bees are from http://food2fork.com

desila
  • 11
  • 5
  • var resultHtml = $("

    Names

    "); for (i = 0; i < result["recipes"].length; i++) { resultHtml.append("
    ") }
    – desila Jun 10 '18 at 08:51
  • I cleaned the code – desila Jun 10 '18 at 08:51
  • Are you calling ajax to a different domain? – M14 Jun 10 '18 at 08:55
  • 1114/5000 I had made a bit of confusion in the code, I'm just approaching javascript, the site from which I want to take the data is http://food2fork.com, the following is the site's response if I type in the browser: http: // food2fork .com / api / search? q = & key = d270f61c8c9fe2ef89633f4b609966de shredded% 20chicken – desila Jun 10 '18 at 09:01
  • {"count": 30, "recipes": [{"publisher": "Closet Cooking", "f2f_url": "http://food2fork.com/view/35171", "title": "Buffalo Chicken Grilled Cheese Sandwich "," source_url ":" http://www.closetcooking.com/2011/08/buffalo-chicken-grilled-cheese-sandwich.html "," recipe_id ":" 35171 "," image_url ":" http: / /static.food2fork.com/Buffalo2BChicken2BGrilled2BCheese2BSandwich2B5002B4983f2702fe4.jpg "," social_rank ": 100.0," publisher_url ":" http://closetcooking.com "}, {" publisher ":" All Recipes "," f2f_url ":" http: //food2fork.com/view/29159 ", – desila Jun 10 '18 at 09:01
  • I would like to format this data – desila Jun 10 '18 at 09:02
  • Log the result and check whether you are getting actual response – M14 Jun 10 '18 at 09:04
  • I did not understand your question – desila Jun 10 '18 at 09:07
  • `No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access`. May be you find the solution [here](https://stackoverflow.com/questions/10636611/how-does-access-control-allow-origin-header-work) – Empty Brain Jun 10 '18 at 09:08
  • ok I try to see the solution that you have given me, thanks – desila Jun 10 '18 at 09:18
  • forgive me, but I do not know where to start, you could help me by modifying my code .... – desila Jun 10 '18 at 09:53

0 Answers0