开发者

Sending a form based on URL string variables

开发者 https://www.devze.com 2023-03-11 10:29 出处:网络
Does anyone know if I can use a different method of calling the page other than: window.location.replace(\"step2.php?cat=\"+index+\"&state=\"+current_state);

Does anyone know if I can use a different method of calling the page other than:

window.location.replace("step2.php?cat="+index+"&state="+current_state);

I really want to do a form submit, preferably using jQuery, eg:

javascript:document.ctl.H开发者_StackOverflow社区05.value='311';
document.ctl.cat="+index+";
document.ctl.state="+current_state”;
document.ctl.submit();

Do you know what the syntax would be for that?


I don't see any jQuery in there. And I think you're looking for ajax; you can check out the MDC doc page for ajax. jQuery has a bunch of ajax related functions. Without more context about your application, the jQuery code to do an ajax request would be:

$.ajax({
    url: 'step2.php',
    data: {cat: index, state: current_state}
});

You could also make a form submit event handler - this way when you click a submit button, the request can be made without the page refreshing:

$('#ctl').submit(function(){
      $.ajax({
        url: 'step2.php',
        data: {cat: index, state: current_state}
    });

    return false; //cancel default form submit action
});

There's also a jQuery plugin to ajaxify form submissions.


There is a QueryString plugin for JQuery: http://plugins.jquery.com/project/query-object which lets you access/modify querystring in an easy way such as

var newUrl = $.query.set("cat", index).set("state", current_state).toString();
0

精彩评论

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

关注公众号