Really strange PHP behavior with AJAX with Jquery
Well, my problems is a little wierd,
I have an AJAX Request to get just a number.
That 开发者_JAVA技巧number is printed on: getMoney.php. On index.php i have the AJAX request.
Ajax Code:
function getMoney(selected)
{
if(selected.value != -1)
{
// Obtener presupuesto via AJAX
$(document).ready(function(){
$.ajax({
url: "getMoney.php",
async: true,
success: function(datos){
//My action
}
});
});
}
}
The function is called when I change a value on a Combobox HTML
<select name="area_id" onchange="getMoney(this);">
Well... My problem: If i write down the numbers on getMoney.php (mannualy) its works perfectly, the AJAX's get it and the action is done, but when i get the numbers from my database i just get 0. I open mannualy too the getMoney.php, and the numbers ARE THERE! even if i get it from the Database.
What's wrong?
make sure that getMoney.php is NOT using your standard view headers, i.e. script includes, stylesheet includes or anything else. Also, it's better practice to have getMoney.php to return a JSON string with your data parametized that way you can pull back diagnosic and error codes as well as specific data. this will help in debugging. look at $.getJSON() if you need help with that.
The XHR object will cache all request by the url, you can fix this by just appending a random string, like this:
$.ajax({
url: "getMoney.php?r=" + new Date().getTime(),
async: true,
success: function(datos){
//Your action
}
});
Install firebug plugin https://addons.mozilla.org/en-US/firefox/addon/1843/ in firefox.
Once you install the plugin, there will be a bug symbol in the right side of the status bar.
Click on it. Then change the select box. There will be a line in the firebug console.
There you can see all the data sent to the server and the response from the server. This will help you identify the issue.
精彩评论