w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
String replace: multiple replace is not working in JQuery
Use global replace with "g" flag: /reg_ex_here/g or new RegExp(exp, 'g') var string = 'bla bla bla'; string.replace(/bla/g, 'ok'); // -> ok ok ok string.replace(new RegExp('bla', 'g'), 'ok'); // -> ok ok ok In your code: var replace_str = 'options\[team_member\]\['+(current-1)+'\]'; rep_block = block.replace(new RegExp(replace_str, 'g'), replace_with);

Categories : Javascript

Replace custom tag inside a string with value from database
Do a database query to get all the values, and put them into an array keyed off the IDs. In the code below, I assume the array is named $tags. $new_string = preg_replace_callback('/{([^}]+)}(.+?){/1}/sim', function ($match) use ($tags) { return $tags[$match[2]]; }, $string); The use ($tags) declaration allows the function to reference the external variable $tags.

Categories : PHP

Replace array keys with values inside a string
try $string= strtr($string,$smileys); This will walk through $string and replace each occurence of each key in $smileys with the associated value. Edit: To include the <img> tags into the string you could post-process the whole string with a single $string=preg_replace('/([w]+.gif)/i','<img src="$1">',$string); This of course relies on the assumption that all your gif names do not contain any blanks and that there are no other words like image.gif in your string since they would be affected too ...

Categories : PHP

Find and replace a string inside an image path
Your stylesheet sample showns the version as "2.0" which is good, because there is a replace function you can use in XSLT 2.0 that will probably do the trick here <xsl:variable name="newurl" select="replace(media:thumbnail/@url,'_s.jpg','_m.jpg')"/> <img src="{$newurl}" style="margin:5px 5px" /> Note that the second argument of the replace function can actually be a regular expression, if you wanted more control over what 's' needed to be replaced. As an aside, do note the correct use of Attribute Value Templates here, signified by the curly braces { }. You use them in outputting the src attribute of the img element, but not within the translate/replace function. Here is the full XSLT in this case: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/

Categories : Xslt

Bash - replace string inside all files in directory
I would do this using sed like so: sed -i "/^[ ]*ODI_SESJA_ID CONSTANT/s/'[^']+'/'REPLACEMENT'/" *.ctl The -i flag to sed means it modifies the files in place, so I usually try it on a single file first with the -e flag instead of the -i flag and confirm that sed's output is what I was looking for. Explanation: The double-quotes protect my regex from the shell. /^[ ]*ODI_SESJA_ID CONSTANT/ matches only the lines that start with whitespace followed by 'ODI_SESJA_ID CONSTANT'. s/'[^']+'/'REPLACEMENT'/ substitutes 'REPLACEMENT' (quoted) for the first quoted portion of the text on matching lines. The document at http://www.catonmat.net/blog/wp-content/uploads/2008/09/sed1line.txt (top Google hit for 'sed one liners' is pretty helpful for quickly dispatching these sort of tasks.

Categories : Bash

How to replace text inside another string which matches a regex pattern
You can use sed echo '${SomeText}, SomeText' | sed "s/${SomeText}/${SomeOtherText}/g" will output ${SomeOtherText}, SomeText if you need to use variables in sed, do it like this a="SomeText" b="SomeOtherText" echo '${SomeText}, SomeText' | sed "s/${$a}/${$b}/g" The output will be the same as above EDIT: Better use arrays to store that strings SomeText[1]="foo" SomeText[2]="bar" i=0 while [[ $i < $MAX_i ]] do ((i++)) sed -i "s/${SomeText[$i]}/${SomeText[$i]}/g" done If you really need your approach, you will need double evaluation SomeText[1]="foo" SomeText[2]="bar" i=0 while [[ $i < $MAX_i ]] do ((i++)) toRepl="SomeText"$i scriptToCall=$(eval echo "s/\${$toRepl}/$`eval echo ${toRepl}`/g") sed -i $scriptToCall file done So you iterate

Categories : Bash

SQL Server : use LIKE inside a CASE statement to replace characters in string
Assuming there is no better rule; i.e. the text is not always at the end of the string, you could store the ignore tokens in a table, join and examine; ;with ignore(token) as ( --a real table is better select 's5' union select 'ind' union select 'cr' ) select distinct id, -- need > 1 col case when ignore.token is null then description else '' end from table left join ignore on description like '%' + token + '%'

Categories : Sql Server

Search and replace formatted properties inside Java string
Use this instead: String regex = "\$\{([^}]*)\}"; Then you obtain only the content between ${ and } that is inside the capture group 1. Note that the $ as a special meaning in a pattern: end of the string Thus it musts be escaped to be seen as literal (as curly brackets).

Categories : Java

how do you call getJSON inside the highchart section
You only add your button when the chart is created. The problem is that when you use the following code , new Highcharts.StockChart..., the chart will load again, so it's will render without your button. So, you have two options, add a callback that will add the button again, or use serie.setData to change it's data dinamically. I'd go with the second option. Other problem is that the response is an array, you have to access it the following way data[0] Finally will have the following code: chart_1DButton = chart.renderer.button('1D', 52, 10, function () { $.getJSON('db_memory.php', function (data) { // update data // chart.series[0].setData( data[0].data ); // update series' options chart.series[0].update(data[0]); }); unselectButtons();

Categories : Javascript

jQuery + regular expression to replace href and src values inside textarea
You don't need a regex to do that. You just have to concatenate the current url and the website url. $('textarea').each(function(){ var obj = $(this); obj.find('a').attr('href', 'http://www.sitename.com' + obj.find('a').attr('href')); obj.find('img').attr('src', 'http://www.sitename.com' + obj.find('img').attr('src')); });

Categories : Javascript

Jquery replace a string of html
target all .fullProfile links, get the href, as it seems like that should be the name of the anchor, and replace the closest wrapping UL with the new anchor : $('.fullProfile').each(function() { var new_anchor = $('<a />', {name : $(this).attr('href'), 'class':'letter', text : $(this).attr('href') }); $(this).closest('ul').replaceWith(new_anchor); });

Categories : Jquery

How to replace particular string from a multiline textarea using jQuery?
Try this to make sure you capture all occurrences, and not just the ones on the first line: $('#service-field').val(currentValue.replace(/particular string/g, "")); Or with a variable: var t = "particular string"; $('#service-field').val(currentValue.replace(eval("/" + t + "/g"), ""));

Categories : Javascript

How replace query string values using jQuery?
use replace function like this : function getParameterByName(name) { name = name.replace(/[[]/, "\[").replace(/[]]/, "\]"); var regex = new RegExp("[\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search); return results == null ? "" : decodeURIComponent(results[1].replace(/+/g, " ")); } var min_price_original=getParameterByName('min-price').replace('%2C',''); var max_price_original=getParameterByName('max-price').replace('%2C','');

Categories : Javascript

Using jQuery find string A or B and replace based on css class and ID
With what I understand of your problem, I'd suggest: $('#nav').contents().each(function(){ if (this.nodeType === 3) { var str = this.nodeValue; this.nodeValue = str.replace(/(|)|(s+|s+)/g,'foobar'); } }); JS Fiddle demo. References: jQuery: contents(). each(). 'Plain' JavaScript: JavaScript regular expressions. Node.nodeType. Node.nodeValue.

Categories : Jquery

Jquery regex replace opening and closing tags is in string
You just need to escape slash in the </div>. And (.*) is regular expression for any possible characters. So this will work: content = content.replace(/<div id="image_insert">(.*)</div>/g, 'test'); Have a look: http://jsfiddle.net/J84nt/1/

Categories : Javascript

Replace string on myBB forum (textare) when key is pressed - jQuery
It's a jQuery object, that's why .replace wont work. You need to add .val() to get the actual value, then you have to set it as well: var value = $("#message").val(); value = value.replace(str,"[b]"+str+"[/b]"); $("#message").val(value);

Categories : Jquery

jQuery getJSON only once per session
Yes, you can do it by using HTML5 localstorage, Below code may help you, $(document).ready(function() { if(typeof(Storage)!=="undefined" && localStorage.fb_count) { $('#fb_count').html(localStorage.fb_count); } else{ $.getJSON('https://graph.facebook.com/<username>?callback=?', function(data) { var fb_count = data['likes'].toString(); $('#fb_count').html(fb_count); if(typeof(Storage)!=="undefined") localStorage.fb_count=fb_count; }); } }); Read http://www.w3schools.com/html/html5_webstorage.asp And http://www.w3.org/TR/webstorage/

Categories : Javascript

jQuery $.getJSON() Fails
Your return looks like this : mycallback({ "test": "variable", "test2": "variable2" }) while a valid json would be: { "test": "variable", "test2": "variable2" } A valid json can only start with an array sign [ or an object sign { you can validate any json string on http://jsonlint.com

Categories : Jquery

std::regex to find word within brackets inside a string, then replace it (and the brackets)
You can use a Regex of something like: @"^[VARIABLEA]$"which will get you a match when you parse through your strings. You can also use the .split() or Regex.split() method to split your strings into arrays on a delimiter SEE: http://www.dotnetperls.com/split Then just replace where you find your match.

Categories : C++

Replace DIV inside another DIV with TEXTAREA, edit text and replace back
You can try like this example javascript: $("#edit").live("click",function(){ $(".inputbox").val($("#menu").text()).show(); $("#menu").hide(); $("#save").show(); $(this).hide(); }); $("#save").live("click",function(){ $("#menu").show(); $("#menu b").html($(".inputbox").val()); $(".inputbox").hide(); $("#edit").show(); $(this).hide(); });

Categories : Jquery

I want to replace content inside a String which starts with # if it starts with !# it must skip it
Use a negative lookbehind? String test = "Hello #Admin Welcome this is Your welcome page !#Admin This is #Admin"; String out = test.replaceAll("(?<!!)#Admin", "MyAdministrator"); System.out.println("OutPut: "+out); The lookbehind is (?<!!).

Categories : Java

jquery getJSON recursive call
How about something like function loadData(repeat) { var jqxhr = $.getJSON('/Test/GetData', function () {}).done(function () { //Load grid using data in jqxhr into grid //Manipulte data in grid and save in DB // At this point I want to call $.getJSON to refresh the grid if (repeat) loadData(false); }); } loadData(true); This should loop one time.

Categories : Jquery

jquery jqrowl get message from getjson
I'm not sure I understand it well. But you don't need 1 more "each" loop I think. Does the code below suit you ? $.getJSON("json.php", function(data, textStatus, jqXHR) { // if you only put data as input, data variable is an array like [data, textStatus, jqXHR] I think. Thus the "each" function returns you the data, the status and the xhr I think $.each(data.msg, function(index, value) { // for each entry of the msg array, create a notification. "value" is a {"header": "...", "content": "..."} object $.jGrowl( value.message, // here is the notification's content { group: "myhtmlclass", life: 5000, header: value.header, // here is the notification's title } }); }); });

Categories : Jquery

jquery getJSON callback issues
few thinks to look for 1) make sure you have no other error that is blocking the script ... check you developer's tool console if you have any errors.... your above code (jquery getJSON callback issues) looks fine to me (no syntax error as far as i know). 2) make sure the path is correct. anyways if path is incorrect the error should be displayed in the console.. press F12 for developer tools and click on console tab

Categories : Jquery

$.getJSON jquery parsing to HTML
Your JSON is invalid. You are missing quotes around the field names. Try something like this: [ { "first": "Bob", "last": "Jones" }, { "first": "Josh", "last": "Smith" } ]

Categories : Javascript

Jquery getJson Request is getting cancelled
Instead of $.getJSON, you need to use $.ajax({ url:GET_USERS_SEX, dataType: 'jsonp', success:function(json){ // handle the json response }, }); This is because normal JSON responses need to come from the same server. JSONP does not have the cross-domain restriction. Or you could make sure that you are requesting the JSON with the exact same domain name as you use in the browser url.

Categories : Javascript

$.getJSON seems to return as literal string with nested objects
"Stats":{ "ID":"3", "IMG":"/images/player_avatars/player_test.png", "First_Name":"Teddy", "Surname":"Vernall", "Nickname":"Bear", "number":"11", "Fav_Pos_1":"ST", "Fav_Pos_2":"CAM", "team":"A", "SPEED":"100", "AGILITY":"100", "STRENGTH":"100", "JUMP":"100", "MARKING":"100", "STAMINA":"100", "LEADERSHIP":"100", "ADAPTABILITY":"100", "REST...,"SET_PIECES":"100", "THROW_INS":"100", "REFLEXES":"100", "ONE_ON_ONES":"100", "AERIAL_ABILITY":"100", "CATCHING":"100", "COORDINATION":"100", "THROWING":"100", "coordX":0, "coordY":0, "yellowCards":0, "redCards":0, "shotsOnTarget":0, "shotsOffTarget":0, "goals":0, "assists":0, "completedPasses":0, "incompletePasses":0, "tackles":0, "timesTackled":0, "intercepts":0, "intercepted":0, "badReceive":0 } see the SyntaxError: Unexpected token S Your SET_PIE

Categories : PHP

Boost String Replace Doesn't Replace Newline With String
std::getline doesn't read newline characters when it extracts from the stream and so they're newer written in fileContents. Also, you don't need to search and replace " ", streams abstract this away and translate them to ' '.

Categories : C++

Jquery $.ajax json vs. getjson format
Have you looked at the JavaScript console in Firebug or Chrome Dev Tools to see if there is an error? My guess is that the function onSucess_displaycust is undefined within the scope in which you are calling it.

Categories : PHP

JQuery get() or getJSON only work for local files
Typically you can only make an AJAX request (which is what $.getJSON is) on the same domain and protocol as your script. If you wish to make a cross-domain request, you will must use the JSON-P support of $.getJSON, and wrap the data in a callback invocation server side, determined by the query string parameter, ?callback.

Categories : Jquery

jQuery simple getJSON doesn't work
First of all: You have to be sure that your JSON file ( which is regarded in getJSON() ) is accessible and has no any errors. Then use the following snippet: $(document).ready(function(){ $.getJSON('/the/path/to/theJSON',{ format: "json" }).done(function(data){ alert(data.fruit_name); }); });

Categories : Jquery

Dynamic Search using getJSON in jQuery and Laravel 4
You don not register the right URL. Two ways of solving this problem & wrote a little code for better understanding (tune it to your needs) 1. Adjust PHP // Here, modified URL Route::get('searchpeeps', function(){ return Input::get('q'); }); Using this Javascript $(".searchterm").keyup(function(e){ $.getJSON( "searchpeeps", { q: this.value }, function(data) { console.log(data); } ); }); 2. Adjust Javascript $(".searchterm").keyup(function(e){ $.getJSON( "searchpeeps/" + this.value, null, function(data) { console.log(data); } ); }); ... with this PHP Route::get('searchpeeps/{q}', function($q){ return $q; });

Categories : Laravel

jQuery mobile: Wait until $.getJSON is finished
Do $.getJSON("localhost/url", function (data) { $.each(data.reporting_list.reporting, function (i, item) { rows = '<tr><td>' + item.data1 + '</td><td>' + item.data2 + '</td></tr>' }); $('#aaa').append(rows); //move to the page in the callback itself $.mobile.changePage("#homePage"); });

Categories : Jquery

Issue with multiple callbacks getJSON jquery
You need to capture name in the closure, just as you do for marker. $("#loadingDiv").show(); $.getJSON('https://api.site.com/data/'+userID+'',(function(marker, name){ // second call using userID return function(data2) { var info1 = data2.response.tips.items[0].text; var info2 = data2.response.tips.items[1].text; marker.bindPopup("<div class='popup'>" + name +"</br>"+ info1 +"</br>"+ info2 + "</div>", {maxWidth: '600'}) // create the popup and add it to the marker $("#loadingDiv").hide(); } })(marker, name) <div id="#loadingDiv" style="display: none">Loading...</div>

Categories : Javascript

I can't get JSON object from response to getJSON ( jQuery )
i also noticed that your not using the key that is in your json output. $.getJSON('http://172.25.10.99/list2.php', function(data) { $('#responseParagraph').append("<p>"+data.file.filename+"</p>"); });

Categories : PHP

jquery table replace partial table content inside html
You are using the wrong selector. There should be no space between `"td :contains"` ^------- Remove this space Supposed to be $("td:contains('name:')").text("Hello:"); You can also try $("td b:contains('name:')").text("Hello:"); Check Fiddle

Categories : Jquery

Is there any way to use the JQuery GetJSON method to get HTML from an external page?
You can retrieve any JSON object that you have access to with GetJSON. Here is an example with Razor an MVC Controller. jQuery Code $(function () { $.getJSON('@Url.Action("GetColorsJson", "Json")', function (jsonData) { var css = new customContentJs.css.apply(jsonData); }); }); Controller Code using System.Web.Mvc; using DAL; using Newtonsoft.Json; public class JsonController : Controller { private readonly CustomContentContext _db = new CustomContentContext(); /// <summary> /// Return a json serialized object of user saved colors /// </summary> /// <returns></returns> public string GetColorsJson() { return JsonConvert.SerializeObject(_

Categories : Javascript

How to get values from a PHP file querying MongoDB in jQuery's getJSON()?
You want to convert the cursor returned from the find() function to something json_encode can actually use like so: $cursor = $collection->find(array("field2.subfield2" => "value 2")); echo json_encode(iterator_to_array($cursor, false)); This is because the query is not run until you iterate the cursor. Iterator_to_array basically will exhaust the cursor, get all documents, and put them into an array for json_encode. Edit Specifying false as the second $use_keys argument to iterator_to_array() will ensure that the results are indexed numerically (instead of by the _id field of each document).

Categories : PHP

JQuery $.getJSON call not formatting dropdown list
I don't think val() works for <option> tags; it's to get/ set the value of a control, such as SELECT or INPUT, not really to edit an option. Try setting the OPTION value by means of attr('value', someValue) instead. I also think your expectation of jQuery.each() on an object ("map") is wrong. If your above code is mostly working: var dest = $(selobj); console.log('populating data to options', data, dest.length); $.each( data, function(key,value) { console.log(' option', key, value); var el = $('<option></option>') .attr('value', key) .html( value); dest.append( el); }); More logging, and assigning major repeatedly-used & intermediate variables (both for performance, and so you can log/debug them) is

Categories : Jquery

jQuery .getJSON return JSON but can't access by result.key
in php code use: <?php $c = array(array("id"=>1, "medname"=>"Medication No. 1", "qty"=>"2", "pDay"=>"3", "beforeAfterMeal"=>null), array("id"=>3, "medname"=>"Medication No. 2", "qty"=>"1", "pDay"=>"1", "beforeAfterMeal"=>null)); echo json_encode($c, JSON_FORCE_OBJECT); ?> this is the correct json format [ {"id":1, "medname":"Medication No. 1", "qty":"2", "pDay":"3", "beforeAfterMeal":null }, { "id":3, "medname":"Medication No. 2", "qty":"1", "pDay":"1", "beforeAfterMeal":null }, { "id":4, "medname":"Medication 3", "qty":"4", "pDay":"1", "beforeAfterMeal":null } ] then you can use $.getJSON(url).done(function(data) {

Categories : PHP



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.