开发者

trigger Ajax xmlhttp function when submitting form

I would like to trigger an ajax call/object instantiation when i submit a form. Can i do this vie the action="" field?

<FORM id="form" METHOD="GET" ACTION="">
<b> Enter argument: </b>
<input size="40" name="q" id="q" value="">
<INPUT TYPE="submit" id="q" VALUE="Submit">
<INPUT TYPE="reset" VALUE="Reset">
<开发者_JS百科/FORM>

in the same same file i have a function:

function xmlhttpPost(){
...
request = new ajaxRequest()
...
request.open("GET","xmlget.php?url=" + $search + nocache, true)


Add an onclick handler to the submit button, like so:

<INPUT TYPE="submit" id="q" VALUE="Submit" onclick="someJavaScript()">


Have a look at form's onsubmit event. http://www.w3schools.com/jsref/event_form_onsubmit.asp


You can attach an event handler to the form's submit event, and then make your ajax request in the event handler.


You should use onsubmit="function();" Also once you get this working you will also have to prevent the form from submitting according to the "action" jQuery provides event.preventDefault(); which works the best from what I've seen.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜