Can't select text because of AJAX
I have an AJAX chat. AJAX reloads session every 750ms so it deselect text which I selected in chat. How can I solve it?
My code:
document.getElementById('content-frame').onload = msg_loading();
$(document).ready(function(e) {
$.ajaxSetup({
cache: false
});
setInterval(function() {
$('#content-frame').load('<? echo('init/conversation.php?uid='.$id.'&cid='.$u['id']); ?>');
}, 750);
});
ajax chat selection
add a comment |
I have an AJAX chat. AJAX reloads session every 750ms so it deselect text which I selected in chat. How can I solve it?
My code:
document.getElementById('content-frame').onload = msg_loading();
$(document).ready(function(e) {
$.ajaxSetup({
cache: false
});
setInterval(function() {
$('#content-frame').load('<? echo('init/conversation.php?uid='.$id.'&cid='.$u['id']); ?>');
}, 750);
});
ajax chat selection
You can look into the Selection API. What have you tried? Ideally, if you've built the chat yourself, you shouldn't be doing a simple refresh... whatever script you're using should be able to dynamically update any mutated messages or append new messages...
– Sheng Slogar
Nov 19 '18 at 14:48
can you post some code? It's hard to get the context of the problem you are having with that description.
– Josh Woodcock
Nov 19 '18 at 14:50
@JoshWoodcock I edited the code. Check it please.
– Nudger app
Nov 19 '18 at 15:15
add a comment |
I have an AJAX chat. AJAX reloads session every 750ms so it deselect text which I selected in chat. How can I solve it?
My code:
document.getElementById('content-frame').onload = msg_loading();
$(document).ready(function(e) {
$.ajaxSetup({
cache: false
});
setInterval(function() {
$('#content-frame').load('<? echo('init/conversation.php?uid='.$id.'&cid='.$u['id']); ?>');
}, 750);
});
ajax chat selection
I have an AJAX chat. AJAX reloads session every 750ms so it deselect text which I selected in chat. How can I solve it?
My code:
document.getElementById('content-frame').onload = msg_loading();
$(document).ready(function(e) {
$.ajaxSetup({
cache: false
});
setInterval(function() {
$('#content-frame').load('<? echo('init/conversation.php?uid='.$id.'&cid='.$u['id']); ?>');
}, 750);
});
ajax chat selection
ajax chat selection
edited Nov 19 '18 at 15:14
Nudger app
asked Nov 19 '18 at 14:39
Nudger appNudger app
14
14
You can look into the Selection API. What have you tried? Ideally, if you've built the chat yourself, you shouldn't be doing a simple refresh... whatever script you're using should be able to dynamically update any mutated messages or append new messages...
– Sheng Slogar
Nov 19 '18 at 14:48
can you post some code? It's hard to get the context of the problem you are having with that description.
– Josh Woodcock
Nov 19 '18 at 14:50
@JoshWoodcock I edited the code. Check it please.
– Nudger app
Nov 19 '18 at 15:15
add a comment |
You can look into the Selection API. What have you tried? Ideally, if you've built the chat yourself, you shouldn't be doing a simple refresh... whatever script you're using should be able to dynamically update any mutated messages or append new messages...
– Sheng Slogar
Nov 19 '18 at 14:48
can you post some code? It's hard to get the context of the problem you are having with that description.
– Josh Woodcock
Nov 19 '18 at 14:50
@JoshWoodcock I edited the code. Check it please.
– Nudger app
Nov 19 '18 at 15:15
You can look into the Selection API. What have you tried? Ideally, if you've built the chat yourself, you shouldn't be doing a simple refresh... whatever script you're using should be able to dynamically update any mutated messages or append new messages...
– Sheng Slogar
Nov 19 '18 at 14:48
You can look into the Selection API. What have you tried? Ideally, if you've built the chat yourself, you shouldn't be doing a simple refresh... whatever script you're using should be able to dynamically update any mutated messages or append new messages...
– Sheng Slogar
Nov 19 '18 at 14:48
can you post some code? It's hard to get the context of the problem you are having with that description.
– Josh Woodcock
Nov 19 '18 at 14:50
can you post some code? It's hard to get the context of the problem you are having with that description.
– Josh Woodcock
Nov 19 '18 at 14:50
@JoshWoodcock I edited the code. Check it please.
– Nudger app
Nov 19 '18 at 15:15
@JoshWoodcock I edited the code. Check it please.
– Nudger app
Nov 19 '18 at 15:15
add a comment |
1 Answer
1
active
oldest
votes
Personally I would be reloading the data via ajax on the page that contains the chat. Like so:

Right now you have your chat box reloading from the "Main page" which I think is the problematic part. I would use ajax to call a REST API instead. This will solve your problem with the page reloading and deselecting the text because the page is not reloading, the data is being updated via ajax.
setInterval(function(){
$.ajax({
url: '/conversation-rest-api.php?uid=' + uid
})
.done(function(data){
// Use templating tool to generate html from `data`
// var content = getContentFromData(data);
$('#content-output').html(content);
});
}, 750);
but content-frame isn't iframe :(
– Nudger app
Nov 19 '18 at 18:15
If you aren't using iframe you can just skip the "conversation" page. The main thing here is I think you should be using a REST API and generating the html in the javascript instead of your php page. You can use something like Mustache for templating.
– Josh Woodcock
Nov 19 '18 at 18:20
Can you please make new answer and write there example code of that REST API?
– Nudger app
Nov 19 '18 at 18:38
A REST API returns a JSON payload instead of an HTML payload, I'm sure you can do the research yourself on this.
– Josh Woodcock
Nov 19 '18 at 18:50
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376941%2fcant-select-text-because-of-ajax%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Personally I would be reloading the data via ajax on the page that contains the chat. Like so:

Right now you have your chat box reloading from the "Main page" which I think is the problematic part. I would use ajax to call a REST API instead. This will solve your problem with the page reloading and deselecting the text because the page is not reloading, the data is being updated via ajax.
setInterval(function(){
$.ajax({
url: '/conversation-rest-api.php?uid=' + uid
})
.done(function(data){
// Use templating tool to generate html from `data`
// var content = getContentFromData(data);
$('#content-output').html(content);
});
}, 750);
but content-frame isn't iframe :(
– Nudger app
Nov 19 '18 at 18:15
If you aren't using iframe you can just skip the "conversation" page. The main thing here is I think you should be using a REST API and generating the html in the javascript instead of your php page. You can use something like Mustache for templating.
– Josh Woodcock
Nov 19 '18 at 18:20
Can you please make new answer and write there example code of that REST API?
– Nudger app
Nov 19 '18 at 18:38
A REST API returns a JSON payload instead of an HTML payload, I'm sure you can do the research yourself on this.
– Josh Woodcock
Nov 19 '18 at 18:50
add a comment |
Personally I would be reloading the data via ajax on the page that contains the chat. Like so:

Right now you have your chat box reloading from the "Main page" which I think is the problematic part. I would use ajax to call a REST API instead. This will solve your problem with the page reloading and deselecting the text because the page is not reloading, the data is being updated via ajax.
setInterval(function(){
$.ajax({
url: '/conversation-rest-api.php?uid=' + uid
})
.done(function(data){
// Use templating tool to generate html from `data`
// var content = getContentFromData(data);
$('#content-output').html(content);
});
}, 750);
but content-frame isn't iframe :(
– Nudger app
Nov 19 '18 at 18:15
If you aren't using iframe you can just skip the "conversation" page. The main thing here is I think you should be using a REST API and generating the html in the javascript instead of your php page. You can use something like Mustache for templating.
– Josh Woodcock
Nov 19 '18 at 18:20
Can you please make new answer and write there example code of that REST API?
– Nudger app
Nov 19 '18 at 18:38
A REST API returns a JSON payload instead of an HTML payload, I'm sure you can do the research yourself on this.
– Josh Woodcock
Nov 19 '18 at 18:50
add a comment |
Personally I would be reloading the data via ajax on the page that contains the chat. Like so:

Right now you have your chat box reloading from the "Main page" which I think is the problematic part. I would use ajax to call a REST API instead. This will solve your problem with the page reloading and deselecting the text because the page is not reloading, the data is being updated via ajax.
setInterval(function(){
$.ajax({
url: '/conversation-rest-api.php?uid=' + uid
})
.done(function(data){
// Use templating tool to generate html from `data`
// var content = getContentFromData(data);
$('#content-output').html(content);
});
}, 750);
Personally I would be reloading the data via ajax on the page that contains the chat. Like so:

Right now you have your chat box reloading from the "Main page" which I think is the problematic part. I would use ajax to call a REST API instead. This will solve your problem with the page reloading and deselecting the text because the page is not reloading, the data is being updated via ajax.
setInterval(function(){
$.ajax({
url: '/conversation-rest-api.php?uid=' + uid
})
.done(function(data){
// Use templating tool to generate html from `data`
// var content = getContentFromData(data);
$('#content-output').html(content);
});
}, 750);
edited Nov 19 '18 at 18:49
answered Nov 19 '18 at 18:13
Josh WoodcockJosh Woodcock
1,5851016
1,5851016
but content-frame isn't iframe :(
– Nudger app
Nov 19 '18 at 18:15
If you aren't using iframe you can just skip the "conversation" page. The main thing here is I think you should be using a REST API and generating the html in the javascript instead of your php page. You can use something like Mustache for templating.
– Josh Woodcock
Nov 19 '18 at 18:20
Can you please make new answer and write there example code of that REST API?
– Nudger app
Nov 19 '18 at 18:38
A REST API returns a JSON payload instead of an HTML payload, I'm sure you can do the research yourself on this.
– Josh Woodcock
Nov 19 '18 at 18:50
add a comment |
but content-frame isn't iframe :(
– Nudger app
Nov 19 '18 at 18:15
If you aren't using iframe you can just skip the "conversation" page. The main thing here is I think you should be using a REST API and generating the html in the javascript instead of your php page. You can use something like Mustache for templating.
– Josh Woodcock
Nov 19 '18 at 18:20
Can you please make new answer and write there example code of that REST API?
– Nudger app
Nov 19 '18 at 18:38
A REST API returns a JSON payload instead of an HTML payload, I'm sure you can do the research yourself on this.
– Josh Woodcock
Nov 19 '18 at 18:50
but content-frame isn't iframe :(
– Nudger app
Nov 19 '18 at 18:15
but content-frame isn't iframe :(
– Nudger app
Nov 19 '18 at 18:15
If you aren't using iframe you can just skip the "conversation" page. The main thing here is I think you should be using a REST API and generating the html in the javascript instead of your php page. You can use something like Mustache for templating.
– Josh Woodcock
Nov 19 '18 at 18:20
If you aren't using iframe you can just skip the "conversation" page. The main thing here is I think you should be using a REST API and generating the html in the javascript instead of your php page. You can use something like Mustache for templating.
– Josh Woodcock
Nov 19 '18 at 18:20
Can you please make new answer and write there example code of that REST API?
– Nudger app
Nov 19 '18 at 18:38
Can you please make new answer and write there example code of that REST API?
– Nudger app
Nov 19 '18 at 18:38
A REST API returns a JSON payload instead of an HTML payload, I'm sure you can do the research yourself on this.
– Josh Woodcock
Nov 19 '18 at 18:50
A REST API returns a JSON payload instead of an HTML payload, I'm sure you can do the research yourself on this.
– Josh Woodcock
Nov 19 '18 at 18:50
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376941%2fcant-select-text-because-of-ajax%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You can look into the Selection API. What have you tried? Ideally, if you've built the chat yourself, you shouldn't be doing a simple refresh... whatever script you're using should be able to dynamically update any mutated messages or append new messages...
– Sheng Slogar
Nov 19 '18 at 14:48
can you post some code? It's hard to get the context of the problem you are having with that description.
– Josh Woodcock
Nov 19 '18 at 14:50
@JoshWoodcock I edited the code. Check it please.
– Nudger app
Nov 19 '18 at 15:15