English 中文(简体)
2. 如何将 form/aj带入一个表格
原标题:how to post to a form with jquery/ajax
  • 时间:2011-11-11 20:57:36
  •  标签:
  • jquery
  • ajax

我有以下代码,但当我从网页上调取方向时。 我希望能够用jquery/ajax接任,使该网页能够浏览。 谁能向我展示一个 j子吗?

<form id="widget_contact" action="http://www.mysaintssearch.com/?cmd=sb-gimme&from=?cmd=home" method="post">
<input type="text" name="pcode" id="fc_name" />
<input type="hidden" name="hdnCmd" value="sb-gimme" />
<input name="send_button" id="fc_submit" class="btn_b" type="submit" value="Gimme" />
</form>
最佳回答

Take a look at jQuery post():

$.ajax({
  type:  POST ,
  url: url,
  data: data,
  success: success,
  dataType: dataType
});
问题回答

页: 1

<><><><>>><>>>>><>>>>>>

I had to modify the action URL, otherwise it s XSS

<form id="widget_contact" action="/" method="post">
<input type="text" name="pcode" id="fc_name" />
<input type="hidden" name="hdnCmd" value="sb-gimme" />
<input name="send_button" id="fc_submit" class="btn_b" type="submit" value="Gimme" />
</form>

<JAVASCRIPT

$( #widget_contact ).submit(function(e){
    e.preventDefault();
    var form = $(this);

    $.ajax({
        url: form.prop( action ),
        method: form.prop( method ),
        data: form.serialize(),
        success: function(){
            alert( Hurraaaayyy );
        }
    });
});

I highly recommend using the jQuery form plugin.

$( #widget_contact ).submit(function(){ 

    $.post( http://www.mysaintssearch.com/?cmd=sb-gimme&from=?cmd=home , $( #widget_contact ).serialize(), function(data) {
       // data is the variable that s returned from the form page

    });
return false; // so the page won t submit           
});

在我的网站上,我没有做几件事:

form, table, input type submit, input type button, name in identifications unless it is a multiple choice item (like checkbox)

In this case here, specifically, my solution would be:

<div ....>
 <input type="text" id="fc_name" />
 <span id= hdnCmd  style= display:none;   >sb-gimme</span>
 <span onClick= mySubmit();   >SUBMIT</span>
</div>

...
function mySubmit() {
    var myData =  fc_name= +$( #fc_name ).val();
        myData +=  &hdnCmd= +$( #hdnCmd ).text();
    $.post( processingPage.asp , myData, function (data) {
        ... display a returning success or failure
    });
}




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签