开发者

Syntax for passing variables to Jquery.Post() method

I am having a hard time with my comiler passing variables to my .Post method in Jquery...

    $(function () {
    $("#DemoGraphSubmit").click(function (e) {
        e.preventDefault();
        var form = $("#DemoGraphID").serialize();
        var PopID = <% =PopID %>
        var options = [];
        var serializedForm = form.serialize();
        $.post("/PatientACO/SearchByDemographic", {PopID,form}, function (data) {
            options = $.map(data, function (item, i) {
                return "<option value=" + item.Value + ">" + item.Text + "</option>";
            });
            $("#PatientListToAdd").html(options.join(""));
        });
    });
});

The seco开发者_开发问答nd parameter of the $.post() method... It keeps telling me I need a ":"... How does one set up variables and pass them to functions in jquery?


You need to send it as an object or as a query string.

Object:

{ PopID: PopID, form: form }

Query string:

'PopID='+PopID+'&form='+form


The data that you pass to post method can be a well formed json object or a querystring param as below

//json

{ PopID: PopID, form: form }

//string

"PopID="+PopID+"&form="+form;


Figured it out.

{PopID:PopID, form:form}

The compiler stopped throwing hatefull racists messages at me.
Thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜