0

So atm I have this which does work. Basicaly I want to execute the sendTo php file without changing to the new page. The location will cause my page to go to the php one and I don't want this. From the php page I can redirect it back to the original page, but I don't really like to do that. This is just some code added to an old app, it does not need to be pretty, it needs to work.

function showVal(newVal, taskid){
    var sendTo = "update_event.php?id_task=" + taskid + "&done=" + newVal;
    document.location.href = sendTo;
}
2
  • have you consider to use jquery?, query can offer you a solution for that kind of matter, just use .ajax Commented Oct 6, 2015 at 23:10
  • its not worth my time to do that. I just need to add that functionality and leave. I can also see what do I have in the php file and write it directly in the jscript. But like I said, I need a quick fix Commented Oct 6, 2015 at 23:13

3 Answers 3

2

You can use jQuery for this, what you need to do is perform an ajax request.

First include jQuery in your page:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

Then in your javascript you can do something like this:

function showVal(newVal, taskid) {
   $.get('update_event.php', { id_task: taskid, done: newVal}, 
       function(returnedData){
            console.log(returnedData);
   });
}
Sign up to request clarification or add additional context in comments.

Comments

2

ok, since you need a quick fix, i assume importing jquery wont be a whole deal this would be an example using ajax...

   function showVal(newVal, taskid){
    $.ajax({url: "update_event.php?id_task=" + taskid + "&done=" + newVal;, success: function(result){
        //here you can do things with the return result, for example, if you want to display it inside a div
            $("#div1").html(result);
        //or if you just want to alert it 
            alert(result);

        // if you dont want to do anithing, just leave the result in blank.

    }});

if you dont want to download jquery, you can just link it with this link

   <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

hope it helps.

Comments

2

Quick and dirty from the dark ages of web development, just hide a blank iFrame somewhere in the page, and go like this:

function showVal(newVal, taskid){
    var sendTo = "update_event.php?id_task=" + taskid + "&done=" + newVal;
    document.getElementById('yourhiddenframe').src = sendTo;
}

If you need to check for execution, look into onLoad for the iFrame.

1 Comment

i would not recomend it, but i give you +1 since it answers exactly the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.