2012-02-16 63 views
0

我有一个数组在PHP中,我有一个输入字段,我想知道如何让我的值在输入字段中的数组?需要发布到PHP和jQuery数组?

array(
"message"=>$_POST['test'], 
"others"=>"blah" 
) 

<input type="text" id="putIntoArray" > 
<a href="#" onclick="jqueryPOST(this.value);">Post</a> 

function jqueryPOST(value){ 
    var message = $("#putIntoArray").val(); 
    //I dont know how to put this value into "message" array? 
} 

因此,与邮政链接,它应该把输入值放入数组“消息”,但不知道如何?这也是最好的方法吗?

谢谢!

回答

0
$.post('url_here',{ parameter:value, parameter:value, parameter:value}); 

like in your case - DEMO

<input type="text" id="putIntoArray" > 
<a href="#" id="post">Post</a>​ 

//attaching click handler 
$('#post').on('click',function(){ 
    jqueryPOST(); 
}); 

function jqueryPOST() { 

    var message = $("#putIntoArray").val(); 

    //the something you didn't know :) 

    $.post('/echo/json/', { 
     test: message   //<<<HERE's test! 
    }, function() { 

     //what you want to do after? 
     alert('posted!'); 

    }); 

}​ 
+0

怎么样$ _ POST [ '测试']? – hellomello 2012-02-16 07:08:46

+0

我有一个数组了,我不是要创建一个数组。我试图将输入值推送到现有的数组中。 – hellomello 2012-02-16 07:09:26

+0

oops,将参数错误地命名。更新。 – Joseph 2012-02-16 07:10:05

0

可以使用出任@joseph说,或者您可以使用

$.ajax({ 
      type: "POST", 
      url : "your url for posing data", 
      data:"test="+value, 
     }); 
+0

你甚至可以使用'$ .post()',那么你不必指定类型。 – Arjan 2012-02-16 07:10:03

+0

如果你注意到我的答案,我说你可以用@joseph表示的方式 和约瑟夫建议$ .post的方式 – Poonam 2012-02-16 07:11:37

+0

我注意到,我只是没有阅读@Joseph的所有答案。 – Arjan 2012-02-16 07:35:43