Calling PHP scripts from Javascript without leaving current page

前端 未结 7 1387
别跟我提以往
别跟我提以往 2021-01-18 14:57

I\'m having some trouble calling PHP scripts from Javascript without leaving the current HTML page (if it is at all possible). I understand it is possible using AJAX, althou

7条回答
  •  孤城傲影
    2021-01-18 15:41

    I understand it is possible using AJAX, although is it possible using Javascript alone?

    If you don't want to use XHR, you could use this ugly hack...

    var request = 'mysql-insert.php',
        image = new Image();
    
    image.onload = function() {
      // Success
    }
    
    image.onerror = function() {
      // Error
    }
    
    image.src = request;
    

    Except that was only really used before widespread use of AJAX (or needing to make a cross domain request).

    I would just use AJAX. jQuery provides some great abstractions for working with XHR.

提交回复
热议问题