HK1186881B - Method and device for data interaction between a server and a client end - Google Patents
Method and device for data interaction between a server and a client end Download PDFInfo
- Publication number
- HK1186881B HK1186881B HK13114277.0A HK13114277A HK1186881B HK 1186881 B HK1186881 B HK 1186881B HK 13114277 A HK13114277 A HK 13114277A HK 1186881 B HK1186881 B HK 1186881B
- Authority
- HK
- Hong Kong
- Prior art keywords
- client
- server
- preset
- character string
- file
- Prior art date
Links
Description
Technical Field
The present application relates to the field of internet, and in particular, to a method and an apparatus for data interaction between a server and a client.
Background
Generally, when a user accesses a website through a client, a large amount of information may be input into the webpage, in which case, the client is only used to receive the input information of the user, and a large amount of real-time data processing needs to be performed by the server. For example, if a new user who wants to register as a website needs to fill in relevant registration information on a page of the new registered user of a client of the website, if 35 registration information entries and selection boxes on the page exist, the client sends at least 35 HTTP requests to the server; in addition, the quality rating process (e.g., password strength, information filling integrity, etc.) of the input information also needs to be performed by the server, so that such a large, frequent and complex real-time data processing request may cause the following two problems: firstly, the bandwidth of the network is wasted, and the bearing pressure of the server is increased; and secondly, the response speed of the page is influenced, namely, the result after the information processing cannot be rapidly, real-timely and dynamically displayed on the page.
In addition, although the frequent and multiple real-time processing request manner can ensure the consistency of the quality level evaluation processing of the user input information on the logic, the requirements on the hardware, the network bandwidth and the like of the server are high, that is, if the frequent and multiple real-time processing request manner is adopted, the hardware (such as the number of the servers) of the server and the investment of the network bandwidth need to be increased; meanwhile, after the real-time request is processed, the effect of correspondingly and dynamically displaying the returned response data is not very strong in real-time.
Disclosure of Invention
In view of the foregoing drawbacks of the related art, a primary objective of the present application is to provide a method and an apparatus for data interaction between a server and a client, so as to solve the above problems in the related art.
In order to achieve the above object, an embodiment of the present application provides a data interaction method between a server and a client, where the method includes the following steps: s11, presetting an XML data file and a JavaScript file in the server, and creating a webpage to be requested; s12, when a page access request is initiated at the client, the server converts the preset XML data file into a JSON character string, embeds the converted JSON character string and an address link of the preset JavaScript file into the webpage, and sends the webpage to the client; and S13, when the JavaScript file monitors the input information input at the client, processing the JSON character string, and displaying a processing result corresponding to the input information in the webpage.
An embodiment of the present application further provides a data interaction apparatus between a server and a client, where the apparatus includes: the data setting module is used for presetting an XML data file and a JavaScript file in the server and creating a webpage to be requested; the data conversion module is used for converting the preset XML data file into a JSON character string by the server when a page access request is initiated at the client, embedding the converted JSON character string and an address link of the preset JavaScript file into the webpage, and sending the webpage to the client; and the data processing module is used for processing the JSON character string when the JavaScript file monitors the input information input at the client and displaying a processing result corresponding to the input information in the webpage.
In summary, the data interaction method and device between the server and the client can transfer the data processing logic of the server by using the technical advantages of the client, namely, part of data storage and operation tasks of the server are transferred to the client for processing, so that the problems of network delay and server pressure generated by the real-time information input scene of the server and the client when a website is under high concurrency and multiple information input pages are solved; in addition, partial data storage and operation tasks are transferred to the browsing end for execution, so that the times of real-time server interaction between the server and the client are effectively reduced, the network processing delay is reduced, and the potential safety hazard caused by frequent server request is reduced.
Drawings
FIG. 1 is a flowchart illustrating an embodiment of a method for data interaction between a server and a client according to the present application;
fig. 2 is a block diagram illustrating an example of a data interaction apparatus between a server and a client according to the present application.
Detailed Description
Specific embodiments of the present application will be described in detail below. It should be noted that the embodiments described herein are only for illustration and are not intended to limit the present application.
At present, there are many data transmission formats (e.g., XML, JSON, character strings, etc.) between a server and a client, but in order to facilitate data transmission in various different information input scenarios, a popular common standard format, XML, is usually adopted. However, the related art has not solved the problem of lossless conversion and transmission between the server and the client well; in addition, in order to comply with a common standard, the server and the client all adopt uniform XML to transmit data, but because XML is relatively complex in coding and has much redundancy, the capacity of a transmission file is increased, and thus, problems of large network bandwidth occupation, slow analysis speed, delay in displaying dynamic information and the like are caused. Therefore, the data interaction between the server and the client is realized by the method for converting the XML data file into the JSON character string.
Fig. 1 is a flowchart illustrating an embodiment of a data interaction method between a server and a client according to the present application. As shown, the method includes the following steps S11, S12, and S13.
S11, presetting an XML data file and a JavaScript file in the server, and creating a webpage to be requested.
In one embodiment, the developer may preset the XML data file in the server according to different information input scenarios. Here, the XML data file is preset mainly because the XML data file is a basic data file, and the content thereof is relatively fixed. Specifically, taking the newwave network as an example, when registering a newwave member, information such as a mailbox name, a login password, a nickname, an authentication code and the like needs to be filled in, and when registering a newwave microblog user, information such as a mailbox, a password, a nickname, a gender, a location, a name, a certificate number and the like needs to be filled in; therefore, for different information input scenes of the same website, the information content required to be filled in is different; however, for the server of the website, all information required in different information input scenarios needs to be stored, that is, the mailbox name, the login password, the re-input password, the nickname, the verification code, the gender, the location, the name, the certificate number, and other information need to be stored in the XML data file preset in the server in advance.
Here, xml (extensible Markup Language) is an extensible Markup Language which, like HTML, is a subset of SGML (Standard Generalized Markup Language). XML is a simple data storage language that describes data using a series of simple tags that can be created in a convenient manner, and although XML takes up more space than binary data, XML is extremely simple to master and use.
Typically, an XML data file must begin with a document declaration statement, including information such as the version number of the declaration XML, the character set used, and whether it is a stand-alone document, for example: <? xmlversion ═ 1.0 "encoding ═ GB 2312" standby? >; an XML element is composed of a start tag, an end tag, and data content sandwiched between the two tags, and its basic form is as follows: < tag name > data content </tag name >.
Next, the XML data file will be better understood by the following code, wherein the code represents data of provinces in china:
as can be seen from the above encoding, the version number of XML is "1.0", and the character set used is "utf-8" (default encoding). The country "China" includes two provinces of "Heilongjiang" and "Guangdong", the "Heilongjiang" includes two cities of "Harbin" and "Daqing", and the "Guangdong" includes three cities of "Guangzhou", "Shenzhen" and "Zhuhai".
In addition, in one embodiment, the XML data file stores a preset numeric relationship between the XML tree structure and the JSON key-value pair structure, so that when an HTTP page request is triggered at the client as described below, the server performs conversion between the XML data file and the JSON character string according to the numeric relationship, that is, the XML data file is converted into the JSON character string. Therefore, it can be understood that the XML data file preset in the server by the developer corresponds to a table storing a one-to-one numerical relationship between the XML tree structure and the JSON key value pair structure, and is used for associating the preset XML data file with the JSON character string.
Here, json (javascript Object notification) is a lightweight data exchange format. It is based on a subset of JavaScript (Standard ECMA-2623rd Edition-December 1999). JSON employs a text format that is completely language independent, but also uses conventions similar to the C language family (including C, C + +, C #, Java, JavaScript, Perl, Python, etc.). These features make JSON an ideal data exchange language for human reading and writing, as well as for machine parsing and generation.
Specifically, JSON is built on two structures: one is a set of "name/value" pairs, which in different languages is understood as objects (object), records (record), structures (struct), dictionaries (directorary), hash tables (hash tables), key lists (keylist) or associative arrays (associative array), which may be in the form of, for example: { "firstName": "Brett", "lastName": "Marry", "email": com "}; the second is An ordered list of values (ordered list of values), which in most languages is understood as An array (array), which may be of the form, for example:
in the following, the data of province city in china, which is expressed by XML, is converted into a form expressed by JSON character string for comparison with XML, specifically as follows:
from the above two-segment encoding, it is clear that JSON is simpler, shorter, and clearer in encoding and also better in parsing speed than XML, compared to the encoding of XML as described above, and therefore, this is one reason why the present application converts XML data files into JSON strings.
Furthermore, in one embodiment, the JSON string stores a mapping relationship that associates input information with a processing result, and it is noted that the mapping relationship is inherited from an XML data file when the XML data file is converted into the JSON string; thus, when the input information is received at the client as described below, the JavaScript file implements processing of the JSON character string according to the mapping relationship, that is, the input information is associated with the processing result. Therefore, it can be understood that the converted JSON character string corresponds to a table storing a one-to-one mapping relationship between the input information and the processing result, and is used to associate the input information with the processing result.
In one embodiment, the developer also presets a JavaScript file in the server. The JavaScript is an object-based and event-driven client scripting language (i.e., a lightweight programming language), and is also the most popular scripting language on the Internet, which can run in all major browsers (e.g., Internet Explorer, Mozilla, Firefox, Netscape, Opera, etc.), and is typically embedded directly in or adds interactive behavior to HTML pages. Specifically, in one embodiment, the JavaScript file is a separate file, which mainly plays two roles: firstly, monitoring the operation of a user; and secondly, storing program processing logic and accessing the JSON object corresponding to the JSON character string according to the program processing logic. Hereinafter, the above two functions will be described in detail, and thus will not be described in detail.
In addition, since JSON is a subset of JavaScript files, it can convert a set of data represented in the JavaScript file into a string and easily transfer the string between functions, or transfer the string from a client to a server in an asynchronous application, and therefore, it is another reason for this application to convert an XML data file into a JSON string.
In one embodiment, the developer also needs to create a web page to be accessed by the user in the server in advance, which is referred to as an HTML page for understanding, so that the user will link to the HTML page when inputting a website to be accessed in the address bar of the client. For example, taking the newwave network as an example, a developer may create a newwave network home page in a server of the newwave network in advance; when the user inputs the website http:// www.sina.com of the new wave network in the address bar of the client, the home page of the new wave network can be accessed through the address link.
S12, when a page access request is initiated at the client, the server converts a preset XML data file into a JSON character string, embeds the converted JSON character string and an address link of a preset JavaScript file into a webpage, and sends the webpage to the client.
In one embodiment, the server converts the preset XML data file into the JSON string after receiving the HTTP page request triggered by the client from the user for the first time. Here, the HTTP page request refers to a request for an HTML page after a web address is input in an address bar of a client; taking the newwave network as an example, when HTTP:// www.sina.com is input in the address bar of the client and the enter key is pressed, the HTML page jumps to the newwave network home page, which is a so-called HTTP page request.
Furthermore, it is noted that the HTTP page request is only triggered when the user accesses the HTML page for the first time, i.e. the user only needs to trigger the HTTP page request once, or it can also be understood that the HTTP page request is only sent once to the server.
Referring to the above, in an embodiment, assuming that the preset XML data file is < XML > < name >1.5</name > < six >1.2 </six > </XML >, when the HTTP page request is triggered at the client for the first time, the server converts the XML data file into a JSON string { name: 1.5, sex: 1.2}. It should be noted that there are many ways to convert an XML data file into a JSON string, and the conversion can be implemented by a programming language such as Java, C + +, and the like.
Additionally, in one embodiment, the JSON string is used to rank the quality of the input information based on an expert in the row's assessment of the weight that different information takes in various industries. It should be noted that the JSON string is dynamically generated from the XML data file of the server, so that after the XML data file is modified by the server, the dynamically generated JSON string is also modified in the same way when the HTML page is initialized, thereby ensuring the consistency of data. In addition, in the above example, the converted JSON string { name: 1.5, sex: 1.2} also indicates that a score of 1.5 can be obtained when the user name (name) is entered, and a score of 1.2 can be obtained when the gender (sex) is entered.
Specifically, in one embodiment, the JavaScript file may determine the quality level of the input information by counting the score of the input information according to the mapping relationship between the input information and the processing result stored in the JSON character string and comparing the score with a preset quality level standard, and may indicate the quality level of the input information by "star" in the HTML page of the client, and typically, the highest quality level is indicated by five stars (it is it star). Referring to the above, in one embodiment, for example, an HTML page published by company library information of a certain business website is taken as an example; in the HTML page, company information integrity is denoted by "four", and assuming that each star represents a score of 2, five stars represent a full score of 10 (i.e., information integrity of 100%). When a user inputs three items of information, namely a company name, an enterprise type and an operation mode, 0.8 point, 0.6 point and 0.7 point can be obtained correspondingly, the cumulative score of the information input by the user is 2.1 points, an evaluation result of one star can be obtained by comparing the cumulative score with a preset grade quality standard, and at the moment, the completeness of information filling (namely, the quality grade of the input information) can be expressed by one star (star) in an HTML page; if the user also inputs information such as a main operation product, a main operation industry, an operation address, a postcode, a company website, a company brief introduction and the like, 1.0 point, 1.5 points, 0.2 point, 0.5 point and 2.0 points can be obtained correspondingly, the cumulative score of the information input by the user is 8.3 points, and therefore, the completeness of information filling can be represented by four stars (which are all four stars) in an HTML page.
And then, in one embodiment, the address link between the converted JSON character string and the preset JavaScript file is embedded into the bottom of the HTML page, so that the client can easily load the JavaScript file preset in the server to the client through the address link, thereby enabling the JavaScript file to function as described above. Specifically, the JSON string is embedded in the code of HTML in the form of a < script > tag, so that JavaScript files loaded in the HTML can access the JSON string.
And then, in one embodiment, the server sends an HTML page corresponding to the HTTP page request to the client, wherein the HTTP page includes the converted JSON character string and an address link of the JavaScript file.
Referring to the above, in one embodiment, first, it is assumed that an XML data file preset in a server by a developer is < XML > < name >1.5</name > < ip >1.1.1 </ip > </XML >; secondly, when a user triggers an HTTP page request by inputting a website of an HTML page to be accessed in an address bar of a client, the server converts the preset XML data file into a JSON character string { name: 1.5, ip: 1.3, and is embedded into the bottom of the HTML page together with the address connection of the JavaScript file, and finally, the HTML page is sent to the client.
Subsequently, step S121 is further included after step S12 and before step S13.
S121, loading a preset JavaScript file in the client according to the address link embedded in the webpage.
In one embodiment, the client receives and displays an HTML page sent by the server, and loads a preset JavaScript file to the client according to an address link embedded in the HTML page. Therefore, when the user inputs information in the HTML page of the client in real time, the JavaScript file loaded into the client can monitor the operation of the user in time, namely the change on the HTML page, access the JSON character string embedded in the HTML page through the JavaScript language, and dynamically display the processing result to the user.
It should be noted that, in the server, the conversion of the XML data file is implemented using JAVA language; in the client, the JavaScript language is used to access the JSON string, that is, the programming languages used in the server and the client are different.
And S13, when the JavaScript file monitors the input information input at the client, processing the JSON character string, and displaying a processing result corresponding to the input information in a webpage.
Referring to the above, in one embodiment, only after the user triggers the HTTP page request for the first time, the HTML page can be opened in the client, and the user can input information in the HTML page. Continuously, when a user inputs information in the client in real time, the user can directly access the desired JSON character string through the JavaScript file loaded to the client, and does not need to frequently initiate an HTTP page request to the server; that is to say, when the user inputs information in the HTML page in real time, the real-time HTTP page request does not need to be sent to the server, but the JavaScript file loaded into the client can be directly invoked to process the information input by the user in real time and dynamically display the information to the user, so that the load pressure brought to the server by frequent real-time HTTP page requests can be effectively reduced.
The following will specifically describe the data interaction method between the server and the client by taking a company information registration page of a certain business website as an example.
Firstly, a developer presets an XML data file in a server and expresses the XML data file by aa.xml; the XML code of the preset XML data file is specifically as follows:
as can be seen from the above codes, the XML data file includes two parts, namely production process (manufacturer) and distribution wholesale (wolfales), where the production process and the distribution wholesale respectively include: the company name (company name), the main product (product category), the company profile (introduction), the number of staff (staffNum), the operation address (address) and the value (value) corresponding to the stored mapping relation. The above contents are XML data files preset in the server by the developer according to the company information registration scene.
And then, a developer presets a JavaScript file in the server, and the JavaScript file is represented by bb.js, and the JavaScript code of the preset JavaScript file is specifically as follows:
as can be seen from the above codes, the JavaScript file contains program processing logic for JSON character strings, such as eval ('+ jsonStr +'), wherein "jsonStr" represents a JSON character string, and the JSON object corresponding to the JSON character string can be easily accessed by the JavaScript file through the program processing logic.
In turn, the developer will also pre-create an HTML page at the server to be accessed by the user, such as "http:// www.test.com/company/cc.
Secondly, when a user inputs a website to be accessed such as http:// www.test.com/company/cc.html in an address bar of a client for the first time, converting an XML data file preset in a server into a JSON character string, connecting the converted JSON character string and an address of a JavaScript file and embedding the JSON character string and the address of the JavaScript file into the bottom of an HTML page, wherein the HTML page is represented by cc.html, and specific codes are as follows:
as can be seen from the above codes, the HTML page contains the converted JSON character JSON str { "manufacturer": { "company name": 10, "product category": 20, "introduction": 30, "staffNum": 20, "address": 20}, "holeale": { "company name": 15, "product category": 20, "introduction": 25, "staffNum": 30, "address": 10} and the address of the JavaScript file is connected with "bb.js", and the preset JavaScript file can be loaded to the client through the address connection, so that when the user inputs information at the client again, the JavaScript file can monitor the operation of the user, process the request of the user according to the operation of the user, and dynamically display the processing result of the request in an HTML page.
Specifically, assuming that a user selects "production processing" in the "operation mode" and inputs a company name in the "company name", at this time, a request of the user is not sent to the server, but a JavaScript file loaded to the client calls a corresponding JSON character string according to the request of the user, and compares a value 10 corresponding to the character string with a preset score level, and if the value is less than 30, the current star level is 0; if the user further inputs the number of employees, the corresponding value is 30, the cumulative score (score) at this time is 40 (i.e., 10+30), and it can be known that 30 ≦ cumulative score < 45 compared to the preset score, so the current star rating is 1, i.e., it is represented by one red star (—); if the user fills all other information such as the main product, company profile, and management address, the cumulative score should be 100 (i.e., 10+20+30+20+20), and the cumulative score is > -90 compared to the preset score, so the current star rating is 5, i.e., five red stars (it is it is it star).
It should be noted that when the user writes the registration information in the client and clicks the "submit" button, the registration information written by the user is sent to the server, and the server recalculates the accumulated score according to the filling condition of the user and returns the calculation result to the client; that is to say, the whole process only needs to send two requests to the server end at the beginning and the end, so that the problem that HTTP requests are frequently sent to the server due to frequent information input is avoided, the number of real-time interaction between the server and the client is reduced, the network processing delay is reduced, and potential safety hazards caused by frequent server processing requests are also reduced.
According to the technical scheme, the interaction method can transfer the data processing logic of the server by utilizing the technical advantages of the client, namely, partial data storage and operation tasks of the server are transferred to the client for carrying out, so that the problems of network delay and server pressure caused by the fact that the server and the client interact information input scenes in real time when a website is under high concurrency and multiple information input pages are solved; in addition, partial data storage and operation tasks are transferred to the browsing end for execution, so that the number of real-time interaction between the server and the client is effectively reduced, the network processing delay is reduced, and potential safety hazards caused by frequent request of server processing are reduced; in addition, the JSON character string is dynamically generated by the XML data file and can be synchronously changed along with the change of the XML data file, so that the consistency on data processing logic is ensured; furthermore, the quality level of the input information may be rated.
Fig. 2 is a block diagram illustrating an example of a data interaction apparatus between a server and a client according to the present application. As shown in fig. 2, the data interaction device between a server and a client according to this embodiment includes a data setting module 11, configured to preset an XML data file and a JavaScript file in the server, and create a web page to be requested; the data conversion module 12 is configured to, when a page access request is initiated at a client, convert a preset XML data file into a JSON string by the server, embed the converted JSON string and an address link of a preset JavaScript file into a web page, and send the web page to the client; and the data processing module 14 is configured to process the JSON character string when the JavaScript file monitors the input information input at the client, and display a processing result corresponding to the input information in the web page.
In one embodiment, the developer presets an XML data file in the data setting module 11 of the server according to different information input scenarios. Here, the XML data file is preset mainly because the XML data file is a basic data file, and the content thereof is relatively fixed. Specifically, taking the newwave network as an example, when registering a newwave member, information such as a mailbox name, a login password, a nickname, an authentication code and the like needs to be filled in, and when registering a newwave microblog user, information such as a mailbox, a password, a nickname, a gender, a location, a name, a certificate number and the like needs to be filled in; therefore, for different information input scenes of the same website, the information content required to be filled in is different; however, for the server of the website, all information required in different information input scenarios needs to be stored, that is, the information such as mailbox name, login password, re-input password, nickname, verification code, gender, location, name, certificate number, etc. needs to be stored in the JavaScript file in the data setting module 11 in advance.
In one embodiment, the preset XML data file is used for storing a one-to-one corresponding numerical relationship between an XML tree structure and a JSON key value pair structure, so that the preset XML data file is associated with a JSON character string; the data conversion module 12 implements the conversion of the preset XML data file at the server according to the numerical relationship. It can be understood that the XML data file preset in the server by the developer corresponds to a table storing a one-to-one numerical relationship between an XML tree structure and a JSON key-value pair structure, and is used for associating the preset XML data file with the JSON character string.
In one embodiment, the JSON character string is used for storing a mapping relation of the input information and the processing result, so that the input information and the processing result are associated; the data processing module 14 implements processing of the JSON string at the client according to the mapping relationship. It is understood that the converted JSON character string corresponds to a table storing a one-to-one mapping relationship between the input information and the processing result, and is used to associate the input information with the processing result.
In one embodiment, the developer also presets a JavaScript file in the data setting module 11. Here, the JavaScript file is a single file, and mainly plays two roles: firstly, monitoring the operation of a user; and secondly, storing program processing logic and accessing the JSON object corresponding to the JSON character string according to the program processing logic.
Subsequently, in one embodiment, the developer also needs to create an HTML page to be accessed by the user in the data setting module 11 in advance. The HTML page is linked only when the user enters a desired web address in the address bar of the client. For example, taking the newwave network as an example, a developer may create a newwave network home page in a server of the newwave network in advance; when the user inputs the website http:// www.sina.com of the new wave network in the address bar of the client, the home page of the new wave network can be accessed through the address link.
Subsequently, in an embodiment, after the server receives the HTTP page request triggered by the user at the client for the first time, the data conversion module 12 converts the preset XML data file into the JSON character string. Here, the HTTP page request refers to a request for an HTML page after a web address is input in an address bar of a client; taking the newwave network as an example, when HTTP:// www.sina.com is input in the address bar of the client and the enter key is pressed, the HTML page jumps to the newwave network home page, which is a so-called HTTP page request.
Furthermore, it is noted that the HTTP page request is only triggered when the user accesses the HTML page for the first time, i.e. the user only needs to trigger the HTTP page request once, or it can also be understood that the HTTP page request is only sent once to the server.
Referring to the above, in an embodiment, it is assumed that the XML data file preset in the data setting module 11 is < XML > < name >1.5</name > < six >1.2 </six > </XML >, and then, when the HTTP page request is triggered at the client for the first time, the data conversion module 12 converts the XML data file into a JSON character string { name: 1.5, sex: 1.2}.
Additionally, in one embodiment, the JSON string is used to rank the quality of the input information based on an expert in the row's assessment of the weight that different information takes in various industries. Because the JSON character string is dynamically generated by the XML data file of the server, the dynamically generated JSON character string can be modified in the same step when the HTML page is initialized after the XML data file is modified by the server, and thus, the consistency of data can be ensured. In addition, in the above example, the converted JSON string { name: 1.5, sex: 1.2} also indicates that a score of 1.5 can be obtained when the user name (name) is entered, and a score of 1.2 can be obtained when the gender (sex) is entered.
Specifically, in one embodiment, the JavaScript file may determine the quality level of the input information by counting the score of the input information according to the mapping relationship between the input information and the processing result stored in the JSON character string and comparing the score with a preset quality level standard, and may indicate the quality level of the input information by "star" in the HTML page of the client, and typically, the highest quality level is indicated by five stars (it is it star). Referring to the above, in one embodiment, for example, an HTML page published by company library information of a certain business website is taken as an example; in the HTML page, company information integrity is denoted by "four", and assuming that each star represents a score of 2, five stars represent a full score of 10 (i.e., information integrity of 100%). When a user inputs three items of information, namely a company name, an enterprise type and an operation mode, 0.8 point, 0.6 point and 0.7 point can be obtained correspondingly, the cumulative score of the information input by the user is 2.1 points, an evaluation result of one star can be obtained by comparing the cumulative score with a preset grade quality standard, and at the moment, the completeness of information filling (namely, the quality grade of the input information) can be expressed by one star (star) in an HTML page; if the user also inputs information such as a main operation product, a main operation industry, an operation address, a postcode, a company website, a company brief introduction and the like, 1.0 point, 1.5 points, 0.2 point, 0.5 point and 2.0 points can be obtained correspondingly, the cumulative score of the information input by the user is 8.3 points, and therefore, the completeness of information filling can be represented by four stars (which are all four stars) in an HTML page.
In one embodiment, the data conversion module 12 embeds the converted JSON string and the address link of the preset JavaScript file into the bottom of the HTML page, so that the client can easily load the JavaScript file preset in the data setting module 11 to the client through the address link, so that the JavaScript file functions as described above.
Referring to the above, in an embodiment, first, it is assumed that an XML data file preset in the data conversion module 11 of the server by a developer is < XML < name >1.5</name > < ip >1.1.1 </ip > </XML >; next, when the user triggers an HTTP page request by inputting a website of an HTML page to be accessed in an address bar of the client, the data conversion module 12 converts the preset XML data file into a JSON character string { name: 1.5, ip: 1.3, and is embedded into the bottom of the HTML page together with the address connection of the JavaScript file, and finally, the HTML page is sent to the client through the data sending module 13.
In one embodiment, the interaction device further includes a data loading module 13, configured to load a preset JavaScript file in the client according to the address link embedded in the webpage.
In one embodiment, the client receives and displays an HTML page sent by the server, and loads a preset JavaScript file to the client through the data loading module 13 according to an address link embedded in the HTML page. Therefore, when the user inputs information in the HTML page of the client in real time, the JavaScript file loaded into the client can monitor the operation of the user in time, namely the change on the HTML page, access the JSON character string embedded in the HTML page through the JavaScript language, and dynamically display the processing result to the user.
It should be noted that, in the server, the conversion of the XML data file is implemented using JAVA language; in the client, the JavaScript language is used to access the JSON string, that is, the programming languages used in the server and the client are different.
According to the technical scheme, compared with the interaction device in the related art, the interaction device in the embodiment has the characteristics of simple structure, flexible configuration and the like, and can dynamically display the processing result of data.
In summary, the data interaction method and apparatus between the server and the client in this embodiment may utilize technical advantages of the client to transfer data processing logic of the server, so that part of data storage and operation tasks of the server are transferred to the client for execution, thereby solving the problems of network delay and potential safety hazard brought to the server by the server and the client in a real-time information input scenario when a website is under high concurrency and when multiple information input pages are available, and frequent HTTP requests; meanwhile, since the HTTP request is transferred from the server to the client, hardware investment (e.g., increase in the number of servers) is also reduced and network bandwidth is saved; in addition, as the JSON character string is dynamically generated by the XML data file and can be synchronously changed along with the change of the XML data file, the consistency of data processing logic is ensured, and in addition, the quality grade of input information can be evaluated.
While the present application has been described with reference to exemplary embodiments, it is understood that the terminology used is intended to be in the nature of words of description and illustration, rather than of limitation. As the present application may be embodied in several forms without departing from the spirit or essential characteristics thereof, it should also be understood that the above-described embodiments are not limited by any of the details of the foregoing description, but rather should be construed broadly within its spirit and scope as defined in the appended claims, and therefore all changes and modifications that fall within the meets and bounds of the claims, or equivalences of such meets and bounds are therefore intended to be embraced by the appended claims.
Claims (6)
1. A method for data interaction between a server and a client, the method comprising the steps of:
s11, presetting an XML data file and a JavaScript file in the server, and creating a webpage to be requested;
s12, when a page access request is initiated at the client, the server converts the preset XML data file into a JSON character string, embeds the converted JSON character string and an address link of the preset JavaScript file into the webpage, and sends the webpage to the client;
s121, loading the preset JavaScript file in the client according to the address link embedded in the webpage; and
and S13, when the JavaScript file monitors the input information input at the client, processing the JSON character string, and displaying a processing result corresponding to the input information in the webpage.
2. The data interaction method according to claim 1, wherein the preset XML data file is used for storing a one-to-one numerical relationship between an XML tree structure and a JSON key value pair structure, so that the preset XML data file is associated with the JSON character string; the step S12 implements conversion of the preset XML data file at the server according to the numerical relationship.
3. The data interaction method according to claim 1, wherein the JSON character string is used for storing a mapping relation between the input information and the processing result, so that the input information and the processing result are associated; the step S13 implements processing of the JSON string at the client according to the mapping relation.
4. An apparatus for data interaction between a server and a client, the apparatus comprising:
the data setting module is used for presetting an XML data file and a JavaScript file in the server and creating a webpage to be requested;
the data conversion module is used for converting the preset XML data file into a JSON character string by the server when a page access request is initiated at the client, embedding the converted JSON character string and an address link of the preset JavaScript file into the webpage, and sending the webpage to the client;
the data loading module is used for loading the preset JavaScript file in the client according to the address link embedded in the webpage; and
and the data processing module is used for processing the JSON character string when the JavaScript file monitors the input information input at the client and displaying a processing result corresponding to the input information in the webpage.
5. The data interaction device of claim 4, wherein the preset XML data file is used for storing a one-to-one numerical relationship between an XML tree structure and a JSON key value pair structure, so that the preset XML data file is associated with the JSON character string; the data conversion module realizes the conversion of the preset XML data file at the server according to the numerical value relationship.
6. The data interaction device of claim 4, wherein the JSON character string is used for storing a mapping relation between the input information and the processing result, so that the input information and the processing result are associated; and the data processing module realizes the processing of the JSON character string at the client according to the mapping relation.
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201210107292.XA CN103379127B (en) | 2012-04-12 | 2012-04-12 | Data interactive method between server and client and device |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| HK1186881A1 HK1186881A1 (en) | 2014-03-21 |
| HK1186881B true HK1186881B (en) | 2017-08-11 |
Family
ID=
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN103379127B (en) | Data interactive method between server and client and device | |
| US8700803B2 (en) | Web page optimization | |
| US10417058B1 (en) | Method and system for executing application programming interface (API) requests based on parent-child object relationships | |
| US10762095B2 (en) | Validation of log formats | |
| US9672558B2 (en) | Table-form presentation of hierarchical data | |
| WO2017100544A1 (en) | Query processor | |
| US8732159B2 (en) | Generic outer join across database borders | |
| US11734324B2 (en) | Systems and methods for high efficiency data querying | |
| US10997001B2 (en) | Event information processing system | |
| CN105956030A (en) | WEB system and WEB request processing method | |
| US20110035371A1 (en) | Data comparison system | |
| CN116776030A (en) | Gray release method, device, computer equipment and storage medium | |
| CN112052252A (en) | Data query method and device based on associated database | |
| GB2514779A (en) | Information retrieval from a database system | |
| US20150127668A1 (en) | Document generation system | |
| RU2691834C1 (en) | Method of managing web site data | |
| US8676787B2 (en) | Distributed multi-step abstract queries | |
| US20230259519A1 (en) | Dynamic filter and projection push down | |
| US9734529B1 (en) | Method, system, and computer readable medium for selection of catalog items for inclusion on a network page | |
| HK1186881B (en) | Method and device for data interaction between a server and a client end | |
| US20090164515A1 (en) | Method and system for bit streaming for data centric applications | |
| EP4170517B1 (en) | Integrating data with different configuration models | |
| US11663231B2 (en) | Access sharing to data from cloud-based analytics engine | |
| US20170161359A1 (en) | Pattern-driven data generator | |
| US12287837B1 (en) | Generating a path to a document element using machine learning |