我正在编写一个阅读JSON网络服务的小型电子应用程序,我注意到有时会回复#39;对象不发送'结束'事件。知道我做错了什么吗?
另外,我的Web服务可以很好地发送多部分分块数据,我可以看到它作为console.log(BODY: ${chunk}
)的返回。
getDataBtn.addEventListener('click',function(event){
var autoryzator = document.getElementById('autoryzator').value;
var kwartal = document.getElementById('kwartal').value;
var rok = document.getElementById('rok').value;
console.log( `http://go/ankieta/default/purchase_order?approver=${autoryzator}&qtr=${kwartal}&year=${rok}`);
var request = net.request({
method: 'GET',
url: `http://go/ankieta/default/purchase_order?approver=${autoryzator}&qtr=${kwartal}&year=${rok}`,
port: 80
})
var authorize = document.getElementById('authorize');
var jsdata;
var data='';
console.log('connecting ...');
request.on('response', (response) => {
console.log(`STATUS: ${response.statusCode}`)
console.log(`HEADERS: ${JSON.stringify(response.headers)}`)
response.on('data', (chunk) => {
console.log(`BODY: ${chunk}`)
var body = chunk.toString('utf8');
data=data+body
})
response.on('end', () => {
console.log('No more data in response.')
console.log(data)
jsdata=JSON.parse(data);
var data_ = jsdata['data'];
/// some app logic goes here
})
response.on('error', (error) => {
console.log(`ERROR: ${JSON.stringify(error)}`)
ret = JSON.stringify(error);
})
})
request.end();
})

答案 0 :(得分:1)
您可以尝试以下方法:
$(document).ready(function() {
var string = $('.hashtag').html(); // get the content
var result = string.replace("#my_best_friend", "my best friend"); // replace keywords
$('.hashtag').replaceWith( result ); // update the content
});