综合技术

PHP equivalent POST request in AJAX / JQuery

微信扫一扫,分享到朋友圈

PHP equivalent POST request in AJAX / JQuery
0 0

I'm able to send some POST requests to a php file. On this php file, I use this to check if my POST request is what I want:

I would like to know if I can do the same thing in AJAX / JQuery ?

Not something like this:

    $.post("page.php", $("form[name=addMessage]").serialize(), function(data) {
        //Do something here
    }).error(function() {
        //error
    })

EDIT:

I don't want to send POST request in AJAX / JQuery. I just want to check if I receive a POST request, send from another page. Indeed, I send a POST request with a field named "message". And I my question is: Is it possible to check if the field "message" is set, but not in PHP, in AJAX / JQquery.

Thank you so much for your help.

Regards, Lapinou.

If I understand what you are trying to do: No.

Do you want to just listen for an incoming request in Javascript without calling any Ajax-methods? This is not possible. Javascript needs to be told that "I am sending a request now, and I want a response". It is not possible to say "If any request is sent, deal with it here".

Think about it. How would this work? If Javascript would listen to any request incoming, how would it know the difference between an user submitting a form and you sending a request using Postman?

Also, once you load the website in your browser, this is said to be clientside. Everything that happens after that is bound to your computer and your instance of the website. Any request sent to the site would be sent to the server, not your browser.

Hello, buddy!
感谢您的支持!

    原创 | 国产手游不充钱就能变强?这么有毒的鸡你吃过吗?

    上一篇

    DCloud CTO崔红保:如何玩转H5网站快速转换成App?

    下一篇

    您也可能喜欢

    评论已经被关闭。

    插入图片