Skip to content Skip to sidebar Skip to footer

How To Run External Php File Using Ajax And Display Results In Same Page

Right now I'm using below script for button click which opens in new window But what I need is

Solution 1:

AJAX calls are regular requests so any PHP file is automatically executed.

$("output") will select all <output> tags. I suspect you meant an object with ID=output (which is at the bottom of the page)

Here's a corrected js:

$.get( "out.php", function( data ) {
    // replace content of #output with the response
    $( "#output" ).html( "Molecule: " + data.Molecule );
    // append the response to #output//$( "#output" ).append( "Molecule: " + data.Molecule );alert( "Load was performed." );
}, "json" );

If the response is not valid JSON this will cause an error (and not call the alert). If that's the case you can alert and check the response like this:

$.get( "out.php", function( data ) {
    alert( data );
});

This won't expect JSON and therefore not throw an error if it's not valid.

Post a Comment for "How To Run External Php File Using Ajax And Display Results In Same Page"