如何将Ajax发布到类似Twitter的API上

时间:2021-07-20 03:48:49

I am very new to JavaScript and to AJAX. A friend has started helping me with a form that will post a status update to App.net, but I can't get it to work. I'm sure there are many errors in the code, but thanks in advance for any help.

我是JavaScript和AJAX的新手。一位朋友已经开始帮我提供一个可以向App.net发布状态更新的表单,但我无法让它工作。我确定代码中有很多错误,但要提前感谢任何帮助。

<html>
<head>
<title>Post to App.net</title>
<link rel="stylesheet" type="text/css" href="style_post.css">
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>

<body>
<script>
function post()
</script>
<script type="text/javascript" language="javascript" src="count.js"></script>

<form id="post" method="post">
<textarea name="fixlength" value="What's on your mind?" id="posttext" maxlength="256"     lengthcut="true"></textarea><br>
<input type="submit" value="Post" id="submit">
</form>
<label id="limitlbl_0" ><script> parseCharCounts(); </script></label>

<script type="text/javascript">
var frm = $('#post');
var token = window.location.href.substring(45,143),
var text = $('input[type="text"]').val()
frm.submit(function () {
        $.ajax({
            type: 'POST',
            url: 'https://alpha-api.app.net/stream/0/posts',
            data: {
                text: 'test'
                token: + token +'
            },
            success: 
    });

    return false;
});
</script>

</body>
</html>

1 个解决方案

#1


1  

If you are making a larger app then you will definitely need to get the ajax calls working (you can make cross-domain posts as well as gets using CORS). However, for this particular situation, there is a simpler solution:

如果你正在制作一个更大的应用程序,那么你肯定需要让ajax调用工作(你可以制作跨域帖子以及使用CORS)。但是,对于这种特殊情况,有一个更简单的解决方案:

http://developers.app.net/docs/other/web-intents/

Using web intents you can use an iframe or redirect a user to a post form very easily. Just use the right URL and you are done. No JS required at all.

使用网页意图,您可以非常轻松地使用iframe或将用户重定向到帖子表单。只需使用正确的URL即可完成。根本不需要JS。

Here is the example above:

以下是上面的示例:

https://alpha.app.net/intent/post/?text=%40adn%20When%20is%20the%20next%20meetup%3F

#1


1  

If you are making a larger app then you will definitely need to get the ajax calls working (you can make cross-domain posts as well as gets using CORS). However, for this particular situation, there is a simpler solution:

如果你正在制作一个更大的应用程序,那么你肯定需要让ajax调用工作(你可以制作跨域帖子以及使用CORS)。但是,对于这种特殊情况,有一个更简单的解决方案:

http://developers.app.net/docs/other/web-intents/

Using web intents you can use an iframe or redirect a user to a post form very easily. Just use the right URL and you are done. No JS required at all.

使用网页意图,您可以非常轻松地使用iframe或将用户重定向到帖子表单。只需使用正确的URL即可完成。根本不需要JS。

Here is the example above:

以下是上面的示例:

https://alpha.app.net/intent/post/?text=%40adn%20When%20is%20the%20next%20meetup%3F