Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

ofxJSONRPC - cannot load images from JSONRPC registered method

$
0
0

@barelief wrote:

I have js app with thumbnails from 0 to 9. When I press thumbnail it sends integer from 0 to 9 to oF app.

Server registers method which loads a image based on that integer:

(...)

server->registerMethod("set-pic-id",
		"Set a picID",
		this,
		&ofApp::setPicture);

(...)

this works fine:

void ofApp::keyPressed(int key)
{
	loadPicture(ofToString(key-48));
}

this doesn't (image is filled with white):

void ofApp::setPicture(ofx::JSONRPC::MethodArgs& args)
{
	loadPicture(args.params.asString());
	ofLogVerbose("ofApp::setVideo") << args.params.asString();
}

this loads image:

void ofApp::loadPicture(string input)
{
	string bgPath;
	bgPath="images/bg/"+ input +".jpg";
	bg.loadImage(bgPath);
	cout << "image loaded..."<< endl;
}

main.js:

(...)   
 $('.thumb').on('click', function() {
        var $this = $(this);
        JSONRPCClient.call('set-pic-id',
            $(this).attr('id'),
            function(result) {},
            function(error) {
                addError(error);
            });
    });
(...)

html:

(...)
<img class=thumb id=1 />
<img class=thumb id=2 />
(...)

any suggestions?

Posts: 4

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles