title: ios - how to change string in .html file from objective-c and update webview?
body: <p>I'm trying to display some data which I take from my web service with objective-c on highcharts javascript graphic library.</p>
  
  <p>In order to take specific data from web service i used query string which i shape according to user's interactions with ui.</p>
  
  <p>What i couldn't do is, sending resulting url to my html file, so when url is changed resulting data from webservice will change. And It will show new graphic.</p>
  
  <p>Below you can see my htlm file and objective-c code. How can i do this? How can i send dataURL variable from objective-c to serviceDataURL in .html file?</p>
  
  <p>My html file: (all js file importing not included here for making it more readable)</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;script type='text/javascript'&gt;
              var serviceDataURL = "http://xx.xx.xxx.xxx:yy/get_item_data_ios?generic={%22line_ids%22:[],%22measure%22:%221%22,%22db_name%22:%22NPI%22,%22timeoffset%22:433112400000,%22show_total%22:true}";
  
              $(function() {
                  $.getJSON(serviceDataURL, function(data) {
                      // Create the chart
                      window.chart = new Highcharts.StockChart({
                          chart : {
                              renderTo : 'container'
                          },
                          navigation: {
                              buttonOptions: {
                                  enabled: false,
                                  width: 60
                              }
                          },
                          rangeSelector : {
                              buttonSpacing: 20,
                              buttonTheme: { // styles for Q,Y,YTD,ALL buttons
                                  fill: 'none',
                                  stroke: 'none',
                                  'stroke-width': 15,
                                  style: {
                                      color: '#039',
                                      fontWeight: 'bold'
                                  },
                                  states: {
                                      hover: {},
                                      select: {
                                          fill: '#039',
                                              style: {
                                                  color: 'white'
                                              }
                                      }
                                  }
                              },
                              selected : 3, 
                              inputDateFormat: '%Y-%m-%d',
                              inputEditDateFormat: '%Y-%m-%d',
                              buttons:[
                                  {
                                      type: 'month',
                                      count: 3,
                                      text: 'QQ'
                                  },
  
                                  {
                                      type: 'year',
                                      count: 1,
                                      text: 'YY'
                                  },
  
                                  {
                                      type: 'ytd',
                                      text: 'YTD'
                                  },
  
                                  {
                                      type: 'all',
                                      text: 'ALL'
                                  },
                              ]
                          },
                          title : {
                              text : 'My Total Market'
                          },
                          credits: {
                              text: " ",
                              href: " ",
                          },
                          series : [{
                              name : 'Total Market',
                              data : arr,
                              tooltip: {
                                  valueDecimals: 2
                              }
                          }],
                          exporting: {
                              enabled: false
                          }
                      }, function(chart){
                              // apply the date pickers
                              setTimeout(function(){
                                  $('input.highcharts-range-selector').attr('readonly',1); // burda webviewı engelledik
                                  $('input.highcharts-range-selector', $('#'+chart.options.chart.renderTo))
                              },0)
                          });
                  });
              });
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div id="container" style="height: 500px; min-width: 500px;"&gt;&lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>my objective-c code:</p>
  
  <pre><code>- (void) fetchChartData{
  
      ChartRequest *chartRequest = [ChartRequest new];
      chartRequest.measure = @"1";
      chartRequest.db_name = @"NPI";
      chartRequest.line_ids = [self fetchItemIDs];
      chartRequest.show_total = @"true";
      chartRequest.timeoffset = [NSNumber numberWithLongLong:(433112400000)];
  
  
      NSError * err;
      NSData * jsonData = [NSJSONSerialization dataWithJSONObject:chartRequest.toDictionary options:0 error:&amp;err];
      NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  
  
      NSLog(@"jsonString : %@",jsonString);
  
  
      NSString *dataUrl = [NSString stringWithFormat:@"http://xx.xx.xxx.xxx:yy/get_item_data_ios?generic=%@",[Tools urlFriendly:jsonString]];
      NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:dataUrl]];
  
      NSLog(@"\n\n\n\n\n\n\n\n\n\n");
      NSLog(@"dataUrl : %@ ",dataUrl);
  
  
  
      NSString *chartJsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
      NSLog(@"\n \nResponse : %@",chartJsonString);
      [_graphic stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"getJSON(%@, function", chartJsonString]];
  
      //[self displayGrid];
      [self displayhighcharts];
  }
  
  
  
  -(void)displayhighcharts{
      NSString *pathOfFile=[[NSBundle mainBundle] pathForResource:@"indentificated_chart" ofType:@"html"];
      NSString *htmlText=[NSString stringWithContentsOfFile:pathOfFile encoding:NSUTF8StringEncoding error:nil];
  
      NSURL *baseURL = [NSURL fileURLWithPath:pathOfFile];
      [_graphic loadHTMLString:htmlText baseURL:baseURL];
      [alertconnection dismissWithClickedButtonIndex:0 animated:YES];
  }
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
      [self displayhighcharts];
  
      _graphic.scrollView.scrollEnabled = NO;
      [self webViewDidFinishLoad:_graphic];
  
      [self fetchChartData];
  
      textfields=[[NSMutableArray alloc]initWithObjects:_firstchosen,_secondchosen,_thirdchosen,_fourthchosen,_fifthchosen, nil];
  
      [self hiddenfirst];
  }
  
  
  -(IBAction)goButton:(id)sender{
  
      NSString *pathOfFile;
      NSString *htmlText;
      NSURL *baseURL;
  
      pathOfFile=[[NSBundle mainBundle] pathForResource:@"indentificated_chart" ofType:@"html"];
      htmlText=[NSString stringWithContentsOfFile:pathOfFile encoding:NSUTF8StringEncoding error:nil];
  
      baseURL = [NSURL fileURLWithPath:pathOfFile];
      [_graphic loadHTMLString:htmlText baseURL:baseURL];
  
      [self fetchChartData];
  
  }
  </code></pre>