lundi 7 mai 2018

Can I Using Array in ajax Javascript?

I'm first at ajax and I want to using array in ajax

What I want is, 1. get data from ajax, 2. add data to new Array. It's all.

$(document).ready(function () { var main_img = new Array();

So, first, I made one new Array and It works very well.

Than I made setting var for my ajax

      var settings = {
    "async": true,
    "crossDomain": true,
    "url": "http://localhost:52273/movie",
    "method": "GET",
    "headers": {
      "cache-control": "no-cache",
      "postman-token": "b39e3106-5289-f828-261f-132e1aba7bf7"
    }
  }

localhost is run in node server.js and I will get data from html.

      $.ajax(settings).done(function (response) {
    $('#content > div.article > div > div.lst_wrap > ul > li > div > a > img', response).each(function(index)
    {
      var k = $(this).attr('src');
      var k2 = k.slice(0, k.indexOf('?'));
      var alt = $(this).attr('alt');

      main_img[index] = k; // this is not working!!!
    });
  });

setting and ajax is run when document.ready,

and I test insert value in out of ajax, it works very well..

so I thought something wrong when I using array in ajax, Please Help me..

Is there I missing something???




Aucun commentaire:

Enregistrer un commentaire