Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

xajax not using variable

Posted on 2009-04-09
5
Medium Priority
?
288 Views
Last Modified: 2013-12-13
Hi,,
I have something wierd going on with xajax.  In the code below, the variables in the $myhtml variable all show up in the response script alert('$myhtml') when sent to the javascript so I know all the values are being retrieved from my query.  The thing i dont undestand is that the only two variables that can be added to the script are $row and $taxid. If I add any of the other variables such as sub = $sub; the response does not get back and nothing happens. I take them out and it works. I tried a second response object and it does not work with any other variables either whether i use either or both of the response objects.  As long as the response object is exactly $objResponse->script("row=$row;taxid = $taxid;alert('$myhtml');"); it works. I need to transfer more than just the two variables. Is there a limit in the response?

Any ideas?

Thanks
$myhtml = " Count: ". $row . " Taxid: ". $taxid . " Legal: " . $sub . " " . $blk . " " . $lot . " Owner: ".$fname . " " . $lname;
$objResponse = new xajaxResponse();
$objResponse->script("row=$row;taxid = $taxid;alert('$myhtml');");
$objResponse->script("sub = $sub;blk = $blk;alert('$myhtml');");
 
return $objResponse;

Open in new window

0
Comment
Question by:ALASKASTREETMASTER
  • 3
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 2000 total points
ID: 24109764
No, there is no limit. $row and $taxid are both numeric, are the other values numeric or strings? If they are strings, they must be within apostrophes in the javascript:

$objResponse->script("sub = '$sub';blk = '$blk';alert('$myhtml');");
0
 

Author Closing Comment

by:ALASKASTREETMASTER
ID: 31568650
Thanks, that worked.  The taxid is a number, but actually a text field in the server. It did not dawn on me to use the apostrophes i thought they were all retrieved the same way since taxid was a text field and $row was a numer.
0
 

Author Comment

by:ALASKASTREETMASTER
ID: 24112256
How would you encode this variable to include line breaks? I have tried <br>, \n, \r\n.

$myhtml = " Count: ". $row . " Taxid: ". $taxid . "\r\n Legal: " . $sub . " " . $blk . " " . $lot . " \r\nOwner: ".$fname . " " . $lname;

$objResponse->script("alert(myhtml = '$myhtml';")

Thanks.
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24112333
You must double the backslashes, because they are consumed first by PHP, then by javascript in the browser.

$myhtml = " Count: ". $row . " Taxid: ". $taxid . "\\r\\n Legal: " . $sub . " " . $blk . " " . $lot . " \\r\\nOwner: ".$fname . " " . $lname;
$objResponse->script("alert('$myhtml');");
0
 

Author Comment

by:ALASKASTREETMASTER
ID: 24112421
not working see new post please..
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question