dongtuo6562 2010-09-02 20:50
浏览 27
已采纳

如何在ajax函数中提交表单?

normally my ajax functions look something like this:

function ajaxCallback(url,functionToRun)
{
if (window.XMLHttpRequest)
  {// code for new browsers
  myXMLlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6 and lower
  myXMLlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
myXMLlhttp.onreadystatechange=functionToRun;
myXMLlhttp.open("POST",url,true);
myXMLlhttp.send();
}

function getItemList(rep, sort_by_column, order_by)
{

ajaxCallback("scripts/get_item.php?rep="+ rep + "&sort_by_column=" + sort_by_column + "&order_by=" + order_by,function()
  {
  if (myXMLlhttp.readyState==4 && myXMLlhttp.status==200)
    {
    document.getElementById("main_area").innerHTML=myXMLlhttp.responseText;
    }
  });
}

I would like to somehow submit a form on that page using ajax, I looked at some tutorials / questions but they all suggest JQuery, but is there a way to include that form as a variable Or another way of submitting it, without jQuery? I can find a way around it, but I thought I'd check to see if there was some simple way of doing it.

  • 写回答

1条回答 默认 最新

  • duanqiao2006 2010-09-02 21:02
    关注

    Pure JavaScript solution would be

    document.getElementById('formid').submit();
    

    or

    document.formname.submit();
    

    EDIT: You should add a JavaScript tag to your question and remove the "php" tag. It really doesn't have anything to do with PHP.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料