0

i have add below code to my usercontroller.php but its give error"Parse error: syntax error, unexpected '<', expecting end of file" how i can do it

<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
var btcs = new WebSocket('wss://ws.blockchain.info/inv');

btcs.onopen = function()
    {
    btcs.send( JSON.stringify( {"op":"addr_sub", "addr":"{{$sendto}}"} ) );
    };

btcs.onmessage = function(onmsg)
{
  var response = JSON.parse(onmsg.data);
  var getOuts = response.x.out;
  var countOuts = getOuts.length; 
  for($usd = 0; usd < countOuts; usd+++)
  {
    //check every output to see if it matches specified address
    var outAdd = response.x.out[usd].addr;
    var specAdd = "{{$sendto}}";
       if (outAdd == specAdd )
       {
       var amount = response.x.out[i].value;
       var calAmount = amount / 100000000;
       $('#messages').prepend("Received " + calAmount + " BTC");
</script>
Waqar Ali
  • 135
  • 8
  • i want to integrate blockchain.info websocket api. as my btc preview code isthere – Waqar Ali Jan 19 '18 at 08:02
  • Usercontroller is a controller. What's the point of adding js code there? Add it to view instead. – u_mulder Jan 19 '18 at 08:05
  • 1
    that is the wrong place to add js code! – Leo Jan 19 '18 at 08:07
  • then please guide how to use it – Waqar Ali Jan 19 '18 at 08:07
  • 2
    Fundamentally you need to understand server side scripting and client side scripting live in two different world. Laravel is a framework runs in server, generating static texts, and output texts into user's browser. This snippet you pasted here is a Javascript and it lives in a browser, not supposed to be inside your userscontroller. I suggest you to revise your PHP scripting skill first? – Lionel Chan Jan 19 '18 at 08:13
  • @WaqarAli Read the Laravel docs. They will hold your hand. –  Jan 19 '18 at 08:13
  • put the code in blade files – Mahdi Younesi Jan 19 '18 at 08:16

1 Answers1

0

i think you can't integrate jquery in controller, because jquery execute on client side and your laravel controller execute on server side. if you want to use jquery so you have to put it in your view page.

ezad
  • 31
  • 6
  • This isn't wrong... are you really putting JavaScript in a php file? One executes on a server, the other on the client. –  Jan 19 '18 at 08:42