local-host 2015-08-24 12:17 采纳率: 100%
浏览 10

如何将两个数据发送到ajax

I want to send two things to my ajax file. The first one is a formular (method POST) and the second is a simple string.

I can send the form like this :

$.post('ajaxDialog.php', $('#sol').serialize(),function(responseObject,ioArgs) ...

And it works but if I try to send two things like that :

$.post('ajaxDialog.php', {$('#sol').serialize(),simpleString},function(responseObject,ioArgs)

I have an error. So I tried to pass $('#sol').serialize() into an array :

var arrayForm = $('#sol').serialize();

I can't get the values of my form with $_POST['fieldName'] with this method. How should I do ?

Thanks !

  • 写回答

1条回答 默认 最新

  • Lotus@ 2015-08-24 12:23
    关注

    serialize returns a url encoded query string, in the format: "key=val&anotherkey=anotherval" To append to it, just add your new key value pair, seperated by an ambersand &:

    $.post('ajaxDialog.php', 
           $('#sol').serialize()+"&somestring="+simpleString,
           function(responseObject,ioArgs){});
    
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号