Form submit using ajax get method to get response back using XMLhttpreq

后端 未结 2 1642
长情又很酷
长情又很酷 2021-01-26 10:31

I have this form that a user choose values from two dropdown menu. The options in select comes from js file and are exchange rates list. I have already created the code that sho

相关标签:
2条回答
  • 2021-01-26 10:59

    I have solved it with help of Quentin. You guys can use this code, but remember to remove all of html that you have after your php code. it causes this error

    Uncaught SyntaxError: row 23 Unexpected token < in JSON at position 4 at JSON.parse () at XMLHttpRequest.xhttp.onreadystatechange

    if you get this, remove all of your html or anything you have after you echo the data you want to send to JS

    0 讨论(0)
  • 2021-01-26 11:04
    <button onclick="loadDoc()" > show graph </button>
    

    When the submit button is clicked, the loadDoc function runs, but before the Ajax response arrives, the form submits and a new page is loaded.

    The new page doesn't including the event handler waiting for the Ajax response.


    Don't use a submit button. Add type="button".

    0 讨论(0)
提交回复
热议问题