admin管理员组文章数量:1325236
Background
I am making a Chrome extension for a webpage. In this webpage, I need to catch the response that the server sends when a user makes a POST request.
Currently, we are using the Observer pattern to check changes on the HTML page, but this is clumsy and it fires several times.
Objective
I need to catch that response, parse its information accordingly, and then base on it do some actions on the page's HTML by changing (adding some colors to some tables, add additional info, etc).
Problem
My issue here, is that I don't know of any JavaScript library or pure method that allows me to listen to server responses, so I can parse them.
What I tried
I tried JavaScript's EventSource
, however for it to work I need to have specific code in the server and that is not an option.
Another research venue was making the request myself using an XHMLRequest
, but then I would have to have a listener on every button on the page so I could stop its default action and perform it via my code, which doesn't sound that good either.
Questions
- Are there any JavaScript tools that allow me to check for server responses and treat them?
Background
I am making a Chrome extension for a webpage. In this webpage, I need to catch the response that the server sends when a user makes a POST request.
Currently, we are using the Observer pattern to check changes on the HTML page, but this is clumsy and it fires several times.
Objective
I need to catch that response, parse its information accordingly, and then base on it do some actions on the page's HTML by changing (adding some colors to some tables, add additional info, etc).
Problem
My issue here, is that I don't know of any JavaScript library or pure method that allows me to listen to server responses, so I can parse them.
What I tried
I tried JavaScript's EventSource
, however for it to work I need to have specific code in the server and that is not an option.
Another research venue was making the request myself using an XHMLRequest
, but then I would have to have a listener on every button on the page so I could stop its default action and perform it via my code, which doesn't sound that good either.
Questions
- Are there any JavaScript tools that allow me to check for server responses and treat them?
- How are you making the POST request from the user? – Pineda Commented Jan 20, 2017 at 10:42
- The user is clicking the button. That is how he is making the post request. – Flame_Phoenix Commented Jan 20, 2017 at 13:39
1 Answer
Reset to default 8How about something like this?
(function(open) {
XMLHttpRequest.prototype.open = function(m, u, a, us, p) {
this.addEventListener('readystatechange', function() {
console.log(this.response);
}, false);
open.call(this, m, u, a, us, p);
};
})(XMLHttpRequest.prototype.open)
You can override open function and then do with response whatever you want.
本文标签: htmlListen to serve response JavaScriptStack Overflow
版权声明:本文标题:html - Listen to serve response JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742166003a2425835.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论