I am trying to run a php file when a javascript function is called and then reload the page, it reloads the page but the php file doesn’t get executed.
function changeR()
{
$.ajax({ url: 'win.php?id=1' });
window.location.reload()
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Do the reload once ajax call is completed. You may use the success event.
keep in mind that success event will be executed if the ajax call is success, if you want to execute some code no matter it is success or error, you may consider,
[complete][1]ordoneAlternatively you can try
window.location.href=window.location.hrefinstead ofwindow.location.reload()Usually folks use ajax to do partial page updates without a page reload. Are you sure you want to reload the entire page after your ajax call ?
EDIT : As per the comment
If you want to pass your php variable value via this ajax call , you can do like this
Set the value to some html element ( ex : a hidden element with id txtID )
Here you are send the value of element in a parameter named
id. You can use firebug or fiddler to see what value is going.More options are here : http://api.jquery.com/jQuery.ajax/