dongxiaoguang9108 2011-07-04 20:43
浏览 24

jQuery在同一个文件中发布变量

I have some variables set in Javascript. Further down the script I want to use these values in PHP. I realise I need to POST/GET them with jQuery, but I don't understand either function fully, even after looking at the manuals.

  1. Could somebody break it down and explain the parameters?
  2. Would I be better off using GET or POST in the instance?
  3. Can the URL specified be the same as the current page e.g. index.php?

Thanks very much for your help.

  • 写回答

2条回答 默认 最新

  • dongping2023 2011-07-04 20:52
    关注

    It's really just a question of style, really.

    GET places all key/value-pairs in the URL field, whereas POST puts it in the HTTP body. Since URLs are limited in length, POST is preferred for longer, larger sets of data or data needing to benefit from TLS/SSL encryption.

    So let's say we have a key: articleID. You want to pass 1 to articleID, so that the backend can contact the database and retrieve the article in question.

    If you make a GET request, you'd invoke the following URL:

    index.php?articleID=1
    

    If you use POST, you'll put the data in the request body itself, so you wouldn't be able to tell what value you sent to the server without opening the packet in question and examining the request.

    You'll find more information on how to perform these requests back at jQuery's reference site. More information about GET and POST.

    You are the architect of the application, so you would know best what method to use. As for contacting the view itself, it's certainly possible albeit questionable from an architectural point of view.

    评论

报告相同问题?

悬赏问题

  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?