小编Gob*_*hna的帖子

将 JSON 响应从 jquery ajax 提取到 html div

我无法将数据检索到 jquery div 元素,但我可以在 firebug 中看到 ajax 响应。

$(document).ready(function () {
    $.ajax({
        url: "https://m.lowes.com/CatalogServices/product/nvalue/v1_0?nValue=4294857975&maxResults=6&showURL=1&rollUpVariants=1&showUrl=true&storeNumber=0595&priceFlag=rangeBalance&showMarketingBullets=1&callback",
        dataType: "jsonp",
        success: function (data) {
            var returnedData = JSON.parse(data);
            $('#result').html(returnedData);
        }
    });
})
Run Code Online (Sandbox Code Playgroud)

这是我的响应。例如我的 url 包含数据 productCount:64 ,我应该从 ajax 成功中提取 productCount 并将其显示在 html div id 结果中

html javascript ajax jquery json

2
推荐指数
1
解决办法
5623
查看次数

状态未定义

我是新来的反应,我收到状态和方法的错误:

./src/App.js
第 5 行:'state' 未定义 no-undef
第 8 行:'inputchangehandler' 未定义 no-undef

这是我的代码,直到现在:

import React from 'react';
import './App.css';

function App() {
state = {
  userInput: ''
}
 inputchangehandler = (event) => {
    this.setState = ({
      userInput: event.target.value
    })
  }
  return (
    <div className="App">
      <input type="text" name="name" 
      onChange={this.inputchangehandler} 
      value = {this.state.userInput}/>
    </div>
  );
}

export default App;

Run Code Online (Sandbox Code Playgroud)

javascript error-handling reactjs

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

javascript ×2

ajax ×1

error-handling ×1

html ×1

jquery ×1

json ×1

reactjs ×1