简体   繁体   English

如何在javascript中在后台发送http请求?

[英]how to send a http request in the background in javascript?

I have a button, the event would be onclick and then the javascript function will send to server the request(for example a rating button on an item), the page should not be redirected, basically I want the event to happen in the background. 我有一个按钮,事件将是onclick然后javascript函数将向服务器发送请求(例如项目上的评级按钮),页面不应该被重定向,基本上我希望事件发生在后台。 How to do that? 怎么做? Please give me some idea or code. 请给我一些想法或代码。

Welcome to the marvelous world of AJAX. 欢迎来到AJAX的奇妙世界。 One of the issues with ajax calls is that different browsers have different implementations of ajax. ajax调用的一个问题是不同的浏览器具有不同的ajax实现。 It's better if you can use a javascript library that abstracts these differences. 如果您可以使用抽象这些差异的JavaScript库,那就更好了。 I'd suggest you to pick up jQuery. 我建议你去拿jQuery。 You can make ajax calls in jQuery using $.get() , $.post() or $.ajax() 你可以使用$.get()$.post()$.ajax()在jQuery中进行ajax调用

看看jQuery.ajax

you can use jquery ajax to achieve your goal. 你可以使用jquery ajax来实现你的目标。 Its quite simple :) 很简单:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM