0

Hello everybody I'm trying to pass a parameter to my controller.php from javascript, but it doesn't pass and gives me error of undefined URL. kindly help me i shall be thankful to you...Here is my code

function JSfunction(assetid)
{
    window.location="controller.php?command=delete&assetid=".assetid;
}

3 Answers 3

7

You're mixing PHP and JS, you use + to concatenate strings in JavaScript

Change the code to this and it should work:

function JSfunction(assetid) {
    window.location="controller.php?command=delete&assetid=" + assetid;
}

What you are doing now is creating a string and accessing the assetid attribute of that string which is undefined.

Sign up to request clarification or add additional context in comments.

Comments

1

you should set window.location to the full URL, not just the relative URL. I.E.

window.location="http://foo.com/controller.php?command=delete&assetid=" + assetid;

BTW, JS uses + to concat, not .

Comments

1
  1. You must include server address, if it is being used locally,it can be denoted by http://localhost/AppName/pages?QueryString.
  2. Concate string with plus sign, dot is used in php script for concatenation.

1 Comment

Actually, most browsers support relative URLs when dealing with window.location

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.