没有调用ajax函数

the ajax function is not called

本文关键字:函数 ajax 调用      更新时间:2023-09-26

我的实际需求是,我想将从aspx页面返回的值检索到html页面。提前感谢

<script type="text/javascript">

  function getCars() {
      alert("ji");
      $.ajax({
          type: "POST",
          url: "http://localhost:1967/WebSite14/Default.aspx",
          data: "{}",
          contentType: "json",
          dataType: "json",
          success: function (response) {
              var cars = response.emp;
              alert("ji");
              $('#output').empty();
              $.each(cars, function (index, emp) {
                  $('#output').append('<p><strong>' + emp.Expiry + ' ' +
                            emp.Expiry + '</strong><br /> Year: ' +
                            emp.Expiry + '<br />Doors: ' +
                            emp.Expiry + '<br />Colour: ' +
                            emp.Expiry + '<br />Price: £' +
                            emp.Expiry + '</p>');
              });
          },
          failure: function (msg) {
              $('#output').append('hi');
          }
      });
  }

请帮帮我,我错了吗?这是我的aspx页面返回的内容,我也不知道该怎么做才能成功:函数(响应)请帮帮我


    {
    "emp": [
        {
            "Name": "Apple",
            "Expiry": 1,
            "Price": 3.99,
            "Sizes": [
                "Small",
                "Mediu",
                "Large"
            ]
        },
        {
            "Name": "Apple",
            "Expiry": 1,
            "Price": 3,
            "Sizes": [
                "Small",
                "Mediu",
                "Large"
            ]
        }
    ]
}

我继续使用这种格式从链接中获取数据,它起到了作用,感谢你们对的支持

if (xmlHttp.readyState==4)
        {
            alert(xmlHttp.status);
            if(xmlHttp.status==200)
            {
            alert("hi");
            var jsondata=eval("("+xmlHttp.responseText+")") //retrieve result as an JavaScript object
            jsonOutput=jsondata.message.result;
            alert(jsonOutput);
            InitializeLeadStorage()
        }
        }