2011-09-26 21 views
0

我在玩mochaUI,并且很难让POST数据正常工作。我有一个表单和一个提交按钮。我正在使用MochaUI.updateContent在面板中工作。在主面板中,我有形式和下面的JS:MochaUI发布数据和MochaUI.update内容

<script type="text/javascript" charset="utf-8"> 
$('stp1btn').addEvent('click', function(e){ 
    MochaUI.updateContent({ 
     element: $('mainPanel'), 
     method: 'post', 
     data: "w=1", 
     url: '/postFile.php', 
     title: 'Test Post Stuff durrrrrr', 
     padding: { top: 8, right: 8, bottom: 8, left: 8 } 
    }); 
}); 
</script> 

哪个职位,然后应该更新同一面板的页面。但是,我无法将其正确发布。即使在上述示例数据仅为“w = 1”的示例中,除了mochaUI中包含的mootools js文件之外,实际发布的内容是“w = 1”:

这是从Firebug的表单数据:

0:w 
1:= 
2:1 
$family[name]:string 
test:function (a,b){return((typeof a=="string")?new RegExp(a,b):a).test(this); 
} 
contains:function (a,b){return(b)?(b this b).indexOf(b a b)>-1:this.indexOf(a)>-1;} 
clean:function(){return this.replace(/\s /g," ").trim(); 
} 
camelCase:function(){return this.replace(/-\D/g,function(a){return a.charAt(1).toUpperCase();});} 
hyphenate:function(){return this.replace(/[A-Z]/g,function(a){return("-" a.charAt(0).toLowerCase()); 
});}[SNIP] 

我使用了一个框架(笨),它不允许查询字符串,从而防止甚至查看目的地php文件后的数据。

页面上的html都是正确的。

我试过用引号和撇号来描述数据。

我搜索了互联网寻找答案的地区。发现山雀,所以它不是一个彻底的清洗。

如果任何人都可以提供一些有关如何/将如何将js注入发布数据的信息,我将非常感激。

回答

1

只是尝试:

$('stp1btn').addEvent('click', function(e){ 
    MochaUI.updateContent({ 
     element: $('mainPanel'), 
     method: 'post', 
     data: { w: 1 }, 
     url: '/postFile.php', 
     title: 'Test Post Stuff durrrrrr', 
     padding: { top: 8, right: 8, bottom: 8, left: 8 } 
    }); 
}); 

MooTools的请求确实与对象文本或以其他方式对数据进行工作 - 即使可以序列的表格元素,所以数据:document.id("formel")是通常很好。

如果mochaui的子类没问题,那么它应该工作。

+0

谢谢Dimitar。那么数据参数是否会期望json?此外,我试图让它序列化的形式,因为这是我想要的最终结果。在你的例子中,你有document.id('form')。这是确切的方式吗?即我尝试了数据:$('form'),它不起作用。在你的例子中,document.id是指什么?还是只是相当于jquery $的mootools呢?非常感谢。 – stormdrain

+0

取决于mootools的版本。如果你在1.2之前 - 1.2.3之前,这是mochaui附带的东西,那么document.id不会是任何东西 - 从那以后,$成为document.id的别名,所以它不会发生冲突。数据需要一个对象,来自元素或值对查询字符串。我会推荐从github最新抓取mochaui,它的过去版本是0.97 –

+0

是的,我正在运行最新版本。我认为这让我感到困惑 - 我在几个例子中看到了$使用。它现在不起作用,但不是我在问题中使用的值对查询字符串? “W = 1”?对于记录,我也尝试过一个类似“w = 1&d = 8”的结果,其中POST是js文件的一部分。再次感谢。 – stormdrain

0
<script type="text/javascript" charset="utf-8"> 
$('stp1btn').addEvent('click', function(e){ 
    var myRequest = new Request({ 
     url: '/le_formDerp.php', 
     onSuccess: function(responseText){ 
      MochaUI.updateContent({ 
       element: $('mainPanel'), 
       content: responseText, 
       title: 'Test Post Stuff durrrrrr', 
       padding: { top: 8, right: 8, bottom: 8, left: 8 } 
      }); 
     }, 
    }).send($('stp1_form').toQueryString()); 
    myRequest.send(); 
}); 
</script> 

hurrrrrr durrrrrr