jquery ajax and php arrays

Posted by sea_1987 on Stack Overflow See other posts from Stack Overflow or by sea_1987
Published on 2010-06-09T15:34:16Z Indexed on 2010/06/09 16:12 UTC
Read the original article Hit count: 423

Filed under:
|
|
|
|

Hi There, I am trying to submit some data to a PHP script, however the PHP scripts expects the data to arrive in a specific format, like this example which is a dump of the post,

Array ( [save] => Add to shortlist [cv_file] => Array ( [849709537] => Y [849709616] => Y [849709633] => Y ) )

The process is currently that a user selects the product they want using checkboxes and then clicks a submit button which fires the PHP scripts,

The HTML looks like this,

div class="row">

                        <ul>
                            <li class="drag_check ui-draggable">
                                <input type="checkbox" id="inp_cv_849709537" name="cv_file[849709537]" class="cv_choice" value="Y">
                            </li>

                            <li class="id"><a href="/search/cv/849709537">849709537</a></li>
                            <div class="disp">
                            <li class="location">Huddersfield</li>
                            <li class="status">
                            Not currently working                               </li>
                            <li class="education">other</li>
                            <li class="role">
                            Temporary                               </li>
                            <li class="salary">£100,000 or more</li>
                            <div class="s">&nbsp;</div>
                            </div>
                        </ul>
                            <dl>
                                <dt>Current Role</dt>
                                <dd>Developer </dd>
                                <dt>Sectors</dt><dt>
                                </dt><dd>
                                    Energy &amp; Utilities, Healthcare, Hospitality &amp; Travel, Installation &amp; Maintenance, Installation &amp; Maintenance                                    </dd>

                                <dt>About Me</dt><dt>
                                </dt><dd></dd>
                                </dl>
                                <div class="s"></div>
                    </div>

I am needing to use AJAX instead now, but I need to send the data to PHP in the format it expects here is what I have so far,

$('#addshortlist').click(function() {
var datastring = ui.draggable.children().attr('name')+"="+ui.draggable.children().val()+"&save=Add to shortlist";
alert(datastring);
$.ajax({
    type: 'POST',
    url: '/search',
    data:ui.draggable.children().attr('name')+"="+ui.draggable.children().val()+"&save=Add to shortlist",
    success:function(){
        alert("Success"+datastring);
    },
    error:function() {
        alert("Fail"+datastring);
    }
}); 
return false;

});

I would really appreciate any help

© Stack Overflow or respective owner

Related posts about php

Related posts about jQuery