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 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类