Value is coming back as Undefined

帅比萌擦擦* 提交于 2019-12-13 03:51:13

问题


I am using jquery datatables to display results on a table and then passing ID as URL parameter, we able to display details of a particular record to user.

So far, this works fine.

However, I have been asked to pass a second url parameter called user and this is presenting problems.

When I run the code, it is no longer displaying details page.

Upon reviewing the code using firebug, I found an error that says:

john is undefined.

john.doe is the value being displayed on the url that looks more like this:

http://mylink.com/viewDetails.php?ID=1235&userName=john.doe

Any ideas what I am doing wrong?

return "<a target='tab' data-tab-name='#RequestDetails' data-tab-index='2' href='viewDetails.php?rID="
       + oObj.aData["ID"] + "&userName=" + <?php echo $user; ?> + "'> " + oObj.aData["ID"] + " </a>";

回答1:


Your code looks like this after being parsed by PHP:

<a target='tab' data-tab-name='#RequestDetails' data-tab-index='2' href='viewDetails.php?rID=" + oObj.aData["ID"] + "&userName=" + john + "'> " + oObj.aData["ID"] + " </a>

That means it's looking for a variable called john, which as you can see is undefined.

It should be this:

<a target='tab' data-tab-name='#RequestDetails' data-tab-index='2' href='viewDetails.php?rID=" + oObj.aData["ID"] + "&userName=<?php echo $user?>'> " + oObj.aData["ID"] + " </a>




回答2:


You need to but quotes around the php element as it is just going to write out the value of itself to the page. This way it becomes a string.

return "<a target='tab' data-tab-name='#RequestDetails' data-tab-index='2' href='viewDetails.php?rID="
       + oObj.aData["ID"] + "&userName=" + "<?php echo $user; ?>" + "'> " + oObj.aData["ID"] + " </a>";

Better put is this way...

return "<a target='tab' data-tab-name='#RequestDetails' data-tab-index='2' href='viewDetails.php?rID="
       + oObj.aData["ID"] + "&userName=<?php echo $user; ?>'> " + oObj.aData["ID"] + " </a>";


来源:https://stackoverflow.com/questions/24087258/value-is-coming-back-as-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!