Display PHP output in Ajax Popup

老子叫甜甜 提交于 2019-12-04 23:06:28

Add $('.popup-with-form').magnificPopup('open'); to your stateChanged function as below. Works for me on your example. Changed both results spans and opens the pop up.

function StateChanged() {
   if (XmlHttp.readyState == 4 || XmlHttp.readyState == "complete") {
       $('.popup-with-form').magnificPopup('open');
      document.getElementById("CalcSum").innerHTML = XmlHttp.responseText;
      document.getElementById("CalcSumPopup").innerHTML = XmlHttp.responseText;
   }
}

Update: more documentation here http://dimsemenov.com/plugins/magnific-popup/documentation.html if you need it.

Is the html for the Ajax popup on the same page as the form? If so, add

<span id="CalcSumPopup">Results:</span>

to the popup where you want the result to go and add

document.getElementById("CalcSumPopup").innerHTML = XmlHttp.responseText;

after document.getElementById("CalcSum").innerHTML = XmlHttp.responseText; in Calc.js.

If it is not on the same page this will not work.

EDIT: This works because id's are meant to be unique. getElementById will find the first occurrence of the specified id and then stop, so if you want multiple places to be changed you need to give them unique id's.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!