小编Sud*_*noi的帖子

使用qwest.js的AJAX发布请求goo.gl url shortener api

我正在尝试使用goo.gl URL Shortener API缩短URL,这是一个开源库(qwest.js).我已经使用jquery成功实现了它,但它给了我错误"这个API不支持解析表单编码的输入." 当使用qwest完成时.

我的代码用jquery:

var longURL = "http://www.google.com/";
 $.ajax({
        url: 'https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyANFw1rVq_vnIzT4vVOwIw3fF1qHXV7Mjw',
        type: 'POST',
        contentType: 'application/json; charset=utf-8', 
        data: '{ longUrl:"'+ longURL+'"}',         
        success: function(response) {
          console.log(response)
        }
 })
.done(function(res) {
    console.log("success"); 
})
.fail(function() {
    console.log("error");
})
.always(function() {
    console.log("complete");
});
Run Code Online (Sandbox Code Playgroud)

和qwest.js的非工作代码

var longURL = "http://www.google.com/"    
qwest.post('https://www.googleapis.com/urlshortener/v1/url?key=479dfb502221d2b4c4a0433c600e16ba5dc0df4e&',
    {longUrl: longURL}, 
    {responseType:'application/json; charset=utf-8'})
                    .then(function(response) {
                        // Make some useful actions
                    })
                    .catch(function(e, url) {
                        // Process the error
                    });
Run Code Online (Sandbox Code Playgroud)

强烈建议任何帮助.

javascript ajax jquery google-url-shortener

4
推荐指数
1
解决办法
1437
查看次数

在应用程序中未定义环境变量

我有env var SERVER_URL=localhost:8000

config.js

export const SERVER_URL = process.env.SERVER_URL;

export { SERVER_URL as default };
Run Code Online (Sandbox Code Playgroud)

和行动:

function fetchData(apiUrl, timeout) {
    return timeoutPromise(timeout || 15000, fetch(`${SERVER_URL}${apiUrl}`))
        .then(checkHttpStatus)
        .then(parseJSON);
}
Run Code Online (Sandbox Code Playgroud)

但是在使用之后fetchData我得到了http://localhost:8000/undefined/some_api

来自这里的idk undefined

javascript reactjs redux-form

3
推荐指数
1
解决办法
2790
查看次数

C++ 2D Array - 对于数组下标,出错无效类型'int [int]'

我试图在C++中使用2D数组创建MxN矩阵.

createMatrix()函数请求矩阵项的用户输入,printMatrix()函数必须打印矩阵.

但打印任务不起作用(我无法访问创建的数组,我不明白为什么)

我收到错误:

matrix.cpp:35:20: error: invalid types ‘int[int]’ for array subscript
    cout << matrix[i][j];
Run Code Online (Sandbox Code Playgroud)

我正在使用的代码是:

#include "iostream"
using namespace std;

// user input matrix
int createMatrix(int m, int n){
    int arr[m][n];
    for(int i = 0; i < m; i++){
        for(int j = 0; j < n; j++){
            cout << "A[" << i << "][" << j << "] : ";
            cin >> arr[i][j];
        }
        cout << endl;
    }
    return arr[m][n];
}

/*
void printMatrix(int matrix[][2], int m, int n){ …
Run Code Online (Sandbox Code Playgroud)

c++ arrays

0
推荐指数
1
解决办法
424
查看次数