开发者

JQuery $.getJSON runs the first time, then never again

I have a button click function that is to run a $.getJSON when the button is clicked. It gets some values from a controller posts those to some form fields and opens a modal that contains the form. The first time I click the button it runs the $.getJSON posts the values and opens the modal just fine. when i close the modal and click the button again. It just opens the modal and the values are the old values. It doesn't run the $.getJSON again. I know it doesn't also because I put a break point in the controller. It hits the break point that first time. But won't go into the controller the other times until I completely reload the page.

here is my button click script

   $('[id^=edit]').but开发者_运维知识库ton().click(function () {
    var selected = $(this).val();
    var arr = selected.split(',');
    var item = arr[0];
    var parent = arr[1];
    $("#itemspan").text(parent);
    $("#parentspan").text(item);
    $("#partno")[0].value = item;
    $("#parent")[0].value = parent;
    var url = $("#itemdetailsjsonurl").attr("href");
    var fullurl = url + '/' + item + '/' + parent;
    $.getJSON(fullurl, null, function (data) {
        $("#qty")[0].value = data.qty;
        $("#startdate")[0].value = data.sdate;
        $("#enddate")[0].value = data.edate;
        $("#notes")[0].value = data.memo;
    });

    $("#edtbomitem").dialog('open');
});

any ideas why?


By default it gets cached by the browser. You can use the ajax stack of jQuery to set it off: http://api.jquery.com/jQuery.ajax/.

cache
Default: true, false for dataType 'script' and 'jsonp' If set to false it will force the pages that you request to not be cached by the browser.

Grz, Kris.


The click event has already fired so jQuery stops listening for the click.

Try: $('[id^=edit]').button().live('click', function () {


My guess is that after you get back your information from the server, you're not hooking up your button onclick event.

So either use the .live syntax, or re-wire it up by hand after your call to the server.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜