The native function is being called from the button press (name=="login").
The request is being initialized.
The request callback is being called.
The data (html) is being downloaded.
The javascript function (changeContent) is being called.
No method I have tried thus far to get the html to that function to be displayed has worked.
The alert box which should be displaying some content is displaying "undefined".
In my V8Handler:
- Code: Select all
else if (name == "login")
{
CefRefPtr<CefRequest> request = CefRequest::Create();
// Set the request URL.
request->SetURL("somesite.com/'somescript.php");
// Set the request method. Supported methods include GET, POST, HEAD, DELETE and PUT.
request->SetMethod("POST");
const std::string& upload_data = "";
CefRefPtr<CefPostData> postData = CefPostData::Create();
CefRefPtr<CefPostDataElement> element = CefPostDataElement::Create();
element->SetToBytes(upload_data.size(), upload_data.c_str());
postData->AddElement(element);
request->SetPostData(postData);
// Create the client instance.
CefRefPtr<MyRequestClient> client = new MyRequestClient(0, app_, object);
// Start the request. MyRequestClient callbacks will be executed asynchronously.
CefRefPtr<CefURLRequest> url_request = CefURLRequest::Create(request, client.get(), NULL);
}
In my request client:
- Code: Select all
class MyRequestClient : public CefURLRequestClient {
public:
MyRequestClient(int request_type, CefRefPtr<Application> app = NULL, CefRefPtr<CefV8Value> object = NULL)
: upload_total_(0),
download_total_(0),
app_(app),
request_type_(request_type),
object_(object){}
virtual void OnRequestComplete(CefRefPtr<CefURLRequest> request) OVERRIDE {
CefURLRequest::Status status = request->GetRequestStatus();
CefURLRequest::ErrorCode error_code = request->GetRequestError();
CefRefPtr<CefResponse> response = request->GetResponse();
//Login request
if (request_type_ == 0)
{
//download_data_ IS populating with html from the request
object_->SetValue("newHtml", CefV8Value::CreateString(download_data_), V8_PROPERTY_ATTRIBUTE_NONE);
//changeContent IS being called
app_->browser_->GetMainFrame()->ExecuteJavaScript("changeContent();", app_->browser_->GetMainFrame()->GetURL(), 0);
}
}
The relevant javascript:
- Code: Select all
$(".loginBtn").click(function (e) {
e.preventDefault();
$("#loginPlaceholder").html("<img src=\"img/loading.svg\" style=\"width: 42px;\"></img>");
window.login();
});
function changeContent()
{
alert(window.newHtml);
}