Calling External API with Javascript

前端 未结 5 1808
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-14 03:33

I need to make a POST request to an external server from my webpage using Javascript. The body and response are both json. I can\'t figure out how to make this call or what tool

5条回答
  •  梦谈多话
    2021-02-14 04:18

    You can use JQUERY and AjAX. You can send/get information information to/from your API either by post or get method.

    It would be something like that:

    $("#ButtonForm").click(function(){
    $.ajax({
            url:(Your url),
            dataType:'json',
            type: 'post',
            data: yourForm.serialize(),
            success:function(response){
                  ** If yout API returns something, you're going to proccess the data here.
            }
        });
    });
    

    Ajax: http://api.jquery.com/jquery.ajax/

提交回复
热议问题