s_avinash_s Posted November 4, 2018 Share Posted November 4, 2018 Hi I have 7 to 8 tabs in my code and interacting to server using ajax for getting dynamic data every 1 sec. Since am requesting more data every 1 sec it is slowing down the content and it lags. So is it possible to update only that tab which user clicks.I mean among 7 to 8 tabs user cant view all tabs at the same time. So he views one by one based on his requirement. So how to make only the clicked tab to get dynamic data. Please suggest Link to comment Share on other sites More sharing options...
Funce Posted November 7, 2018 Share Posted November 7, 2018 You could track which one the user has clicked by using a variable. Send that along with your request for data, and make sure your server only sends back the data for that one page. You'll just also need to send a request when the user clicks on a new tab (so they don't see the old data) in addition to the interval requests. Link to comment Share on other sites More sharing options...
s_avinash_s Posted November 7, 2018 Author Share Posted November 7, 2018 Hi Usually i use ajax to get data every 1 sec for a particular variable as shown below and call that function using setInterval. <p class = "modify" id="demo11"></p> <script> function temp_val() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("demo11").innerHTML = this.responseText; } }; xhttp.open("GET", "temp_val", true); xhttp.send(); } setInterval(temp_val, 1000); </script> For tab creation , i followed a example from https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_tabs Onclick functionality if i use, then i send to server with that tab name ,..example tab1 xhttp.open("GET", "tab1", true); and from server all the variables of that tab can be placed and receives at web page.Some thing similar to below if i use else if ((NX_HTTP_SERVER_GET_REQUEST == request_type) && (0 == strcmp (resource, "/tab1"))) { memset (g_str_buf, 0, sizeof(g_str_buf)); snprintf (g_str_buf, STR_BUFFER_LEN, "%d", temp_val); nx_http_server_callback_data_send (server_ptr, g_str_buf, sizeof (tab1)); return (NX_HTTP_CALLBACK_COMPLETED); } How to differentiate and keep each variable in required text box after reeving since i will be having a 50 to 100 variables update. Hope you have understood my requirement Link to comment Share on other sites More sharing options...
dsonesuk Posted November 7, 2018 Share Posted November 7, 2018 The questions is! can you retrieve ALL the names and values in one call? combined. If you can achieve that you are on your way to the answer. 1 Link to comment Share on other sites More sharing options...
s_avinash_s Posted November 9, 2018 Author Share Posted November 9, 2018 On 11/7/2018 at 5:42 PM, s_avinash_s said: else if ((NX_HTTP_SERVER_GET_REQUEST == request_type) && (0 == strcmp (resource, "/tab1"))) { memset (g_str_buf, 0, sizeof(g_str_buf)); snprintf (g_str_buf, STR_BUFFER_LEN, "%d", temp_val); nx_http_server_callback_data_send (server_ptr, g_str_buf, sizeof (tab1)); return (NX_HTTP_CALLBACK_COMPLETED); } Hi From above i am planning to get whole data to web page( i need to test). Once i get whole data to web page, how to place each data in its specified location in web page Link to comment Share on other sites More sharing options...
dsonesuk Posted November 9, 2018 Share Posted November 9, 2018 Ideally it should sent as json object with name and value for each, then its just a matter assigning the value using key name to a specific area, using a identifier. Link to comment Share on other sites More sharing options...
s_avinash_s Posted November 9, 2018 Author Share Posted November 9, 2018 Hi Just got some idea about json objects <p id="demo"></p> <script> var myObj, x; myObj = {"name":"John", "age":30, "car":null}; x = myObj.name; document.getElementById("demo").innerHTML = x; </script> but in ajax am receiving data till now as below if (this.readyState == 4 && this.status == 200) { document.getElementById("demo2").innerHTML = this.responseText; } Now how to get data through ajax and json object. My plan is to receive like below else if ((NX_HTTP_SERVER_GET_REQUEST == request_type) && (0 == strcmp (resource, "/tab1"))) { while(i < number) { memset (g_str_buf, 0, sizeof(g_str_buf)); snprintf (g_str_buf, STR_BUFFER_LEN, "%s", variable[number]); nx_http_server_callback_data_send (server_ptr, g_str_buf, sizeof (tab1)); return (NX_HTTP_CALLBACK_COMPLETED); } } How to get it , still its not clear to me Link to comment Share on other sites More sharing options...
dsonesuk Posted November 9, 2018 Share Posted November 9, 2018 Since I don't know how your server would work to return as a JSON, or any other alternative method, I can't help. Link to comment Share on other sites More sharing options...
Funce Posted November 13, 2018 Share Posted November 13, 2018 I don't know how your server-side works (nor am I proficient in C to use it otherwise) so I wouldn't be able to help regarding that half, but the idea is below: You'd need to look into a JSON library for C, or otherwise string manipulate all the values into a big JSON object string. Then you can output the string as a response. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now