-1

I have a page that is not recognising this script:

<div id='userInfo'></div>

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>


<script>
$(document).ready(function(){
    var id = $("#dropdown").find(":selected").val();
    //alert('Select:'); 
    // load it in the userInfo div above
    $('#userInfo').load('data.php?id=' + id);
    $("#dropdown").change(function(){

    // get the selected user's id
    var id = $(this).find(":selected").val();
    //alert('Select:'); 
    // load it in the userInfo div above
    $('#userInfo').load('data.php?id=' + id);

    });
});
</script>

It might recognise the script but the data.php its looking for is not being picked up even though it is in the same directory. The select statement is working fine. I have tried this on two separate servers, it works on one and not on the other. I need it to work on the one its not working on of course.

The one its working on the form is a directory called /form and this one is in a directory called /letters on a subdomain. How do I get it to recognise the where data.php is?

andy
  • 459
  • 2
  • 6
  • 26
  • This answer might be what you are looking for: http://stackoverflow.com/questions/12524228/how-to-load-php-file-into-div-by-jquery – user2921187 Jun 08 '14 at 19:31
  • I've tried that and its not working :-( I did http://mywebsite.co.uk/bro/letters/data.php Any other suggestions? – andy Jun 08 '14 at 19:38

1 Answers1

0

I've been trying to figure this out for some time. Try using relative url, like /data.php. If that doesn't work, there could be an issue with the browser you're working with. Local files do not load through Ajax on the browser for security reasons.

I suggest doing a simple jquery AJAX call with $.ajax(). Send the id as a GET parameter, dynamically generate what you need via JSON, and on success function, fill in your div with what you generated and sent to the client file from your PHP backend. Good luck!