Jump to content

Does this javascript code cause stateless or stateful protocol request?


eaglehopes
Go to solution Solved by kicken,

Recommended Posts

I have a such javascript code in a php file called index.php;

<?php
 include mathfunctions.php;
?>
...
<script>
  var a=10, b=20;
  var stars=<?php echo multiply(a,b); ?>
</script>
  

I learned that there are two types of protocols, stateless(such as HTTP) and stateful (such as FTP). My question is that, when I used above line of code, does this cause my request to use stateful or stateless protocol? Didn't both use HTTP request? Thanks.

 

Edited by eaglehopes
add extra info
Link to comment
Share on other sites

I found  Guawong Miao's blog which defines when request become stateless or stateful. I think my request does not requires server to save any state of user, so it uses stateless protocol, am I right? How can I determine/learn while developing a request, which one use which(i.e. stateless or stateful)? Is there any tool (such as can Chrome's developer tool or wireshark) show that? Which one is the simplest one? Thanks.

Link to comment
Share on other sites

  • Solution

Your JavaScript code doesn't involve a request at all, other than the one to initially load the page which is going to be a standard stateless HTTP request.  The only stateful protocol you would possibly end up using in JavaScript code is a WebSocket.  The rest of the web revolves around stateless HTTP requests.

That blog post has less to do with HTTP and more to do with applications.  HTTP is stateless, but most web applications are not as they rely upon session data to track who is logged in or other details.  That session data makes the application as a whole stateful even if the individual HTTP requests are not.

 

  • Thanks 1
Link to comment
Share on other sites

19 hours ago, kicken said:

Your JavaScript code doesn't involve a request at all

Why I asked this question is that  because of the comments to user Sandeep Kapil's similar code in tight dependency comments of another forum in the internet. I learned that tight dependency occurs when stateful protocol used but someones claim the otherwise. 

Thanks kicken for great answer, but I have difficulty to understand your above statement, why it isn't count as a request? Until your answer I am thinking that I am triggering and requesting/calling the result of the function inside the php file after run it server. Can you explain a little bit more what happens really when my code run, please? Because what I understood that, php code injected into javascript code calls the function inside another file and returns the function's returned result(I am not so quite sure since I experienced that any echoed string value before the return statement will return as a result).

I know that my code does not seem the right way to get/fetch the result of function in another php file and I found at least one disadvantage of using it although it workes as I expected. So, I am not insisting on the "properness" of the code, but I am really curious to learn why it works only sometimes, not always? Thanks. 

Link to comment
Share on other sites

OK, I found the problem why it sometimes work sometimes not : because it is javascript line contains a php code and when page load, first php code run and awkward results comes! Therefore, my above method is not a correct way of calling a function inside a php! So, as kicken said that, it is not a request at all ! It is a just a php code written inside a javascript line ! :D 

Link to comment
Share on other sites

Then the code and  "tight dependency" comments are in another forum page are totaly garbage ! When I saw in there code and it got 46 positive responses, I supposed that it was a working code... but not! Daniele Rugginenti as the last commenter said the correct thing! 

I hope in the future, one internet firm should apply a "correctness filter" to all of search results by the help of user contributions, if not, for learners it will be a waste of time to learn from internet sources. Or everyone should go back to learn from books as it were in the past :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.