如何通过提交表单将$ _POST信息发送到此页面而无需转到该页面?

问题描述:

我使用下面的代码:

$.ajax({ 
    type:'GET', 
    url: 'save_desc.php?scrapbook_name=<?php print(addslashes($scrapbook_name)); ?>, 
    success: function(data){ 
    $("#" + id + "below").html(data); 
    } 
}); 

我怎样才能改变这种由发布它,而不是使用$ _GET方法发送敏感信息(用“特”字)?

注意:我试过使用addslashes,但这对传递带有通配符的字符串没有任何影响。

+0

不要使用和addslashes,用'json_encode()'。 addslashes用于数据库工作,而不是javascript生成。 –

更改type参数为 'POST',或者使用jQuery的post()功能:

$.post(
    'save_desc.php', 
    { scrapbook_name: <?php print(addslashes($scrapbook_name)) }, 
    function(data) { 
     $("#" + id + "below").html(data); 
    } 
); 

http://api.jquery.com/jQuery.post/

在从RoccoC5后评论的顶部,您可以使用jQuery的序列化功能成变量然后使用后的变量

var PostData = $(myform).serialize(); 

$.post("myphppage.php", 
     PostData, 
     function() 
     { 
      //completion code goes here 
     }, 
     "html") 
    .error(alert("error with post")); 

http://api.jquery.com/serialize/

http://api.jquery.com/jQuery.post/