0

I need to send to the embedded device following command as GET method but this value continuouspantiltmove: String(pt) is not properly sent to the CGI script via Google Chrome, as a result it fails.

I cant fix it in CGI script because its not managed by me as its an embedded device.

How can you submit it with iFrame? or correctly via $.get if iframe is not possible.

When i open the URL simply in Google Chrome URL then the CGI script works, but not working with $.get method.

enter image description here

function button_axisleft() {
  if(alr>100) {
    alr = 100;
  }

  if(alr<-100) {
    alr = -100;
  }  
  alr = alr - 1;  
  pt ="'" + alr + "," + aud + "'"; 

  $.get('http://192.168.1.59/axis-cgi/com/ptz.cgi', {
      camera: 1,
      continuouspantiltmove: String(pt),
      imagerotation: 0,
  }, function(msg) {
    console.log('OK');
  });
}

EDIT: working version

// PAN-TILT-ZOOM
// No need to modify in CGI
function button_axisleft() {
  if(alr>100) {
    alr = 100;
  }  
  if(alr<-100) {
    alr = -100;
  }  

  alr = alr - 1;  
  pt =alr + "," + aud;     
  $.get('http://192.168.1.59/axis-cgi/com/ptz.cgi?continuouspantiltmove=' + pt, {
      camera: 1,
      imagerotation: 0,
  }, function(msg) {
    console.log('OK');
  });
}
  • What does this have to do with the title of your post? I don't see where you are trying to send a comma to anything. – elixenide Apr 29 '15 at 04:59
  • I think he means command in the title. –  Apr 29 '15 at 05:00
  • ptz.cgi needs to receive `continuouspantiltmove=-100,-50&other=values`. When we use $.get to send -100,-50 it does not send the comma correctly as a result it fails –  Apr 29 '15 at 05:02
  • 1
    Oh, so you really mean comma, sorry. –  Apr 29 '15 at 05:03
  • YES - sir. you can see attached screen shot is showing the value is not correct where we were trying to send it as `-4,27` –  Apr 29 '15 at 05:04
  • 1
    The value in the screenshot "decodes" to `'-4,0'`. Do you need the `'` (quotes) around your numbers? Otherwise, the commas are URL-encoded to `%2C0`, which I think should be OK to handle server-side. Also, you don't need to use `String`. Just do `continuouspantiltmove: pt` –  Apr 29 '15 at 05:15

1 Answers1

0

Since you mentioned in the comments you want this:

continuouspantiltmove=-100,-50&other=values

Then this will do it:

function button_axisleft() {
    if (alr > 100) {
        alr = 100;
    }

    if (alr < -100) {
        alr = -100;
    }
    alr = alr - 1;
    pt = alr + "," + aud;

    $.get('http://192.168.1.59/axis-cgi/com/ptz.cgi?continuouspantiltmove=' + pt, {
        camera: 1,
        imagerotation: 0,
    }, function (msg) {
        console.log('OK');
    });
}

You had extra single quotes (') around the numbers in your pt variable. And, according to your comment, you don't want those, so I removed them. It also seems that jQuery automatically URL-encodes some characters, such as the comma, and that's why your query string was looking weird. By including the query parameter directly in your URL string, we can skip jQuery's auto-encoding.

However, you should also check this out: Can I use commas in a URL?

Community
  • 1
  • 1
  • 1
    Thanks, its working now. (just for the record. Some people told me i have to do it in CGI modification, which was completely wrong suggestion.) –  Apr 29 '15 at 05:31
  • 1
    Oh no, yeah, it was just an encoding thing. I'm glad this worked for you :) –  Apr 29 '15 at 05:38