douchan6512 2012-06-28 07:32
浏览 61
已采纳

尝试将表单发布到Facebook VIA Ajax和jQuery时出现400(错误请求)错误

I am trying to post an image to a Facebook album using a form in my website. I know I get the correct access token because posting without jQuery and AJAX works fine - but redirects me out of my website. To solve that, I've made a jQuery AJAX post, but this gives me an error I don't understand.

I'm using:

<script type="text/javascript" src="../Components/JQUERY/jquery-1.4.2.min.js"></script>    
<script type="text/javascript" src="../Components/JQUERY/jquery.validate.min.js"></script>

The code is:

  1. Getting the access token and preparing the URL to post to (It is OK, posting without jQuery is uploading the picture to Facebook):

    //....Facebook code for getting the access token...//
    
    // This is the URL that was originally in the form's action tag//
    $image_url= "https://graph.facebook.com/" . $ALBUM_ID . "/photos?"
    . "access_token=" .$access_token;
    
  2. HTML of the form:

    <form name="myform" id="myform" enctype="multipart/form-data" action="" method="POST">
       Please choose a photo:
         <input name="source" type="file"><br/>
       Say something about this photo: <br/>
         <textarea id="fbText" name="message" rows="4" cols="47"> </textarea><br/><br/>
         <input type="submit" name="submit" value="Upload"/><br/>
    </form>
    
    <div id="results"></div>
    
  3. The jQuery Code:

    <script type="text/javascript">
      $(document).ready(function(){
          $("#myform").validate({
              debug: false,
              rules: {
                  message: "required"   
              },
              messages: {
                  message: "Please insert text."
              },
              submitHandler: function(form) {
                  // do other stuff for a valid form
                  $.post('<?php echo $image_url ?>', $("#myform").serialize(), function(data) {
                    $('#results').html(data);
                });
            }
        });
    });
    </script>
    

Pressing the upload button gives me the following error:

enter image description here

What am I doing wrong? Thanks.

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)