"how to json data using $.getjson from a php file?" Code Answer

4

i think instead of using the file adress: "d:xampp/htdocs/conn_mysql.php" you must use an url defined by xampp such as "http://localhost/mytest/conn_mysql.php"

another thing you need to look out is the method. $.getjson (http://api.jquery.com/jquery.getjson/), as its name says, works with the get method. maybe you should try $.post or $.ajax (http://api.jquery.com/jquery.post/).

oh! and to start your script, not all the browsers supports the <body onload="">. furthermore, it waits for the page to be loaded, not the dom, what can give you problems with your scripts sometimes. you should use $('document').ready(function(), that waits for the dom to be loaded. this way:

<script type="text/javascript">
$('document').ready(function()
{

    $.getjson("d:xampp/htdocs/conn_mysql.php", function(json){
    alert("json data: " + json.options);

});
</script>

i hope it can be useful! ^^

By rowan_m on March 26 2022

Answers related to “how to json data using $.getjson from a php file?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.