【问题标题】:Converting CURL to AJAX request将 CURL 转换为 AJAX 请求
【发布时间】:2016-10-10 20:18:06
【问题描述】:

我需要将下面的 CURL 请求转换为 AJAX,

CURL : $ curl -X POST http://textbelt.com/text -d number=5551234567 -d "message=I sent this message for free with textbelt.com"

我写的 AJAX 请求如下:

$.ajax({
    type: 'post',
    url: "http://textbelt.com/text",        
    data: "number=+1********** message='This is a test message!",           

    success:function(response)
    {
        console.log("Success!!");
    },

    error : function(xhr, status, error)
    {
        console.log("Status of error message" + status + "Error is" + error);
    }   

});

我从服务器得到的响应是:

    {
       "success": false,
       "message": "Number and message parameters are required."
    }

谁能指导我正确的方向?

【问题讨论】:

    标签: jquery ajax curl request


    【解决方案1】:
    $.ajax({
    type: 'post',
    url: "http://textbelt.com/text",        
    data: {"number":"+1**********", "message":"This is a test message!"},           
    
    success:function(response)
    {
        console.log("Success!!");
    },
    
    error : function(xhr, status, error)
    {
        console.log("Status of error message" + status + "Error is" + error);
    }   
    
    });
    

    以上应该可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-06
      • 2018-02-16
      • 1970-01-01
      • 2016-05-20
      • 1970-01-01
      • 2017-08-03
      • 2018-04-16
      相关资源
      最近更新 更多